From 08ab28a66cf14707d86e1b3b045b8c1d5e7a3414 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 3 Nov 2017 14:13:39 +0100 Subject: [PATCH] [FIX] sale_expense: fields consistency Use case to reproduce: - Set a product to be expensed - Set the expense_policy to something else than no - Do a delivery order with a picking - Validate the picking -> Delivered quantity to 0 and impossible to create an invoice if the invoice_policy is delivered_quantity It happens due to this commit 48ea59d What does it do: - The move could be generated by an expense. - If the move has 'no' as expense policy thus we won't add it in the invoice Problem we can't guess if the move come from an expense or not (limitation). This commit add an onchange on can_be_expense is order to set the expense policy back to 'no' when the user uncheck it. Courtesy of amoyaux opw-777139 --- addons/sale_expense/__init__.py | 2 ++ addons/sale_expense/models/__init__.py | 4 ++++ addons/sale_expense/models/product_template.py | 13 +++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 addons/sale_expense/models/__init__.py create mode 100644 addons/sale_expense/models/product_template.py diff --git a/addons/sale_expense/__init__.py b/addons/sale_expense/__init__.py index 67dee8c60db..dc5e6b693d1 100644 --- a/addons/sale_expense/__init__.py +++ b/addons/sale_expense/__init__.py @@ -1,2 +1,4 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/addons/sale_expense/models/__init__.py b/addons/sale_expense/models/__init__.py new file mode 100644 index 00000000000..3a8ca74201b --- /dev/null +++ b/addons/sale_expense/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import product_template diff --git a/addons/sale_expense/models/product_template.py b/addons/sale_expense/models/product_template.py new file mode 100644 index 00000000000..5e6299f2548 --- /dev/null +++ b/addons/sale_expense/models/product_template.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + @api.onchange('can_be_expensed') + def _onchange_can_be_expensed(self): + if not self.can_be_expensed: + self.expense_policy = 'no'