diff --git a/l10n_it_delivery_note/models/stock_picking.py b/l10n_it_delivery_note/models/stock_picking.py index 580fe65908cd..f73f07b220ce 100644 --- a/l10n_it_delivery_note/models/stock_picking.py +++ b/l10n_it_delivery_note/models/stock_picking.py @@ -389,6 +389,7 @@ def _get_partners(self): partner_id = self.mapped("partner_id") src_location_id = self.mapped("location_id") dest_location_id = self.mapped("location_dest_id") + picking_type_code = self.mapped("picking_type_code") src_warehouse_id = src_location_id.get_warehouse() dest_warehouse_id = dest_location_id.get_warehouse() @@ -397,16 +398,18 @@ def _get_partners(self): dest_partner_id = dest_warehouse_id.partner_id if not src_partner_id: - src_partner_id = partner_id - - if not dest_partner_id: - raise ValueError( - "Fields 'src_partner_id' and 'dest_partner_id' " - "cannot be both unset." - ) + src_partner_id = ( + self.company_id.partner_id + if picking_type_code == ["outgoing"] + else partner_id + ) - elif not dest_partner_id: - dest_partner_id = partner_id + if not dest_partner_id: + dest_partner_id = ( + self.company_id.partner_id + if picking_type_code == ["incoming"] + else partner_id + ) return (src_partner_id, dest_partner_id)