From 50e425ce02bc7b2476dc9b97286a550e945abdb7 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 19 Mar 2020 14:00:16 +0000 Subject: [PATCH] [FIX] sale: Re-invoicing policy Steps to reproduce the bug: - Let's consider a product P - Let's consider that a draft SO has been created for P with analytic account AA - P can be sold (sale_ok=True) and Re-invoicing policy = 'At cost' - Untick the option 'Can be sold' on P - Create an expense E for P with the analytic account AA - Submit E and try to post the entries Bug: A UserError was raised saying that SO with analytic account AA must validated but P is no more salable. opw:2217773 closes odoo/odoo#48408 X-original-commit: 3db629cbcde9c4c3bbe2874c18e01dd31abe092d Signed-off-by: Simon Goffin (sig) --- addons/sale/models/product_template.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/sale/models/product_template.py b/addons/sale/models/product_template.py index 20ec0bb5449..005bf32a071 100644 --- a/addons/sale/models/product_template.py +++ b/addons/sale/models/product_template.py @@ -46,6 +46,12 @@ class ProductTemplate(models.Model): for product_template in self: product_template.visible_expense_policy = visibility + + @api.onchange('sale_ok') + def _change_sale_ok(self): + if not self.sale_ok: + self.expense_policy = 'no' + @api.depends('product_variant_ids.sales_count') def _compute_sales_count(self): for product in self: