From 29d10d4b862c4b5ba89710b472d515458ad64671 Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Thu, 15 Jul 2021 06:23:44 +0200 Subject: [PATCH] [13.0][IMP] account_invoicing_mode_at_shipping With a picking related to multiple sales order and those sales order with different invoicing mode, the invoicing could happen at the wrong moment or not at all. This change unifies the way the module checks for sales order needed to be invoiced at shipping. --- .../models/stock_picking.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/account_invoice_mode_at_shipping/models/stock_picking.py b/account_invoice_mode_at_shipping/models/stock_picking.py index 26896a9df99..ec6c117d97d 100644 --- a/account_invoice_mode_at_shipping/models/stock_picking.py +++ b/account_invoice_mode_at_shipping/models/stock_picking.py @@ -17,12 +17,18 @@ def action_done(self): picking.with_delay()._invoicing_at_shipping() return res + def _get_sales_order_to_invoice_at_shipping(self): + """Returns sales order to invoice at shipping related to the picking.""" + return self.mapped("move_lines.sale_line_id.order_id").filtered( + lambda r: r.partner_invoice_id.invoicing_mode == "at_shipping" + ) + def _invoice_at_shipping(self): """Check if picking must be invoiced at shipping.""" self.ensure_one() return ( self.picking_type_code == "outgoing" - and self.sale_id.partner_invoice_id.invoicing_mode == "at_shipping" + and self._get_sales_order_to_invoice_at_shipping() ) @job(default_channel="root.invoice_at_shipping") @@ -44,6 +50,5 @@ def _invoicing_at_shipping(self): return invoices or _("Nothing to invoice.") def _get_sales_order_to_invoice(self): - return self.mapped("move_lines.sale_line_id.order_id").filtered( - lambda r: r._get_invoiceable_lines() - ) + sales = self._get_sales_order_to_invoice_at_shipping() + return sales.filtered(lambda r: r._get_invoiceable_lines())