diff --git a/addons/stock_dropshipping/stock_dropshipping.py b/addons/stock_dropshipping/stock_dropshipping.py index 0d29448dd5f..a41760820e3 100644 --- a/addons/stock_dropshipping/stock_dropshipping.py +++ b/addons/stock_dropshipping/stock_dropshipping.py @@ -26,11 +26,20 @@ class sale_order_line(models.Model): class purchase_order(models.Model): _inherit = 'purchase.order' + @api.one + def _check_invoice_policy(self): + if self.invoice_method == 'picking' and self.location_id.usage == 'customer': + for proc in self.order_line.mapped('procurement_ids'): + if proc.sale_line_id.order_id.order_policy == 'picking': + raise Warning(_('In the case of a dropship route, it is not possible to have an invoicing control set on "Based on incoming shipments" and a sale order with an invoice creation on "On Delivery Order"')) + @api.multi def wkf_confirm_order(self): - for po in self: - if po.invoice_method == 'picking' and po.location_id.usage == 'customer': - for proc in po.order_line.mapped('procurement_ids'): - if proc.sale_line_id.order_id.order_policy == 'picking': - raise Warning(_('In the case of a dropship route, it is not possible to have an invoicing control set on "Based on incoming shipments" and a sale order with an invoice creation on "On Delivery Order"')) + """ Raise a warning to forbid to have both purchase and sale invoices + policies at delivery in dropshipping. As it is not implemented. + + This check can be disabled setting 'no_invoice_policy_check' in context + """ + if not self.env.context.get('no_invoice_policy_check'): + self._check_invoice_policy() super(purchase_order, self).wkf_confirm_order()