From cb53485d71771242b67a52c9e30bb35e23b81efa Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Mon, 19 Feb 2018 15:42:53 +0100 Subject: [PATCH] [FIX] sale: reinvoice only vendor bills When validating a vendor bill, we want the product with expense policy set to be reinvoice on the open sales order matching the analytic account of the invoice line. Applying the same mecanism for customer invoice does not make sense, as we might confirm a SO and validate its invoice, we don't want a new SO line to appear (avoid loop). Unfortunately, since a long time, this is possible in Odoo, and really make no sense. We should only take negative analytic lines (coming from vendor bills and expense, not the customer invoice) into account for adding SO line. This commit correct this problem to avoid having many null SO line created on customer invoice validation. All test cases are correctly written, but there was no check to prevent this mecanism to be apply on customer invoice. --- addons/sale/models/analytic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/sale/models/analytic.py b/addons/sale/models/analytic.py index 35731e44f02..eb6ffcf2ac2 100644 --- a/addons/sale/models/analytic.py +++ b/addons/sale/models/analytic.py @@ -41,7 +41,8 @@ class AccountAnalyticLine(models.Model): @api.multi def _sale_postprocess(self, values, additional_so_lines=None): if 'so_line' not in values: # allow to force a False value for so_line - self.with_context(sale_analytic_norecompute=True)._sale_determine_order_line() + # only take the AAL from expense or vendor bill, meaning having a negative amount + self.filtered(lambda aal: aal.amount <= 0).with_context(sale_analytic_norecompute=True)._sale_determine_order_line() if any(field_name in values for field_name in self._sale_get_fields_delivered_qty()): if not self._context.get('sale_analytic_norecompute'):