diff --git a/addons/point_of_sale/tests/test_anglo_saxon.py b/addons/point_of_sale/tests/test_anglo_saxon.py index 8ddc0110063..c4b37211008 100644 --- a/addons/point_of_sale/tests/test_anglo_saxon.py +++ b/addons/point_of_sale/tests/test_anglo_saxon.py @@ -24,12 +24,13 @@ class TestAngloSaxonCommon(common.TransactionCase): self.account = self.env['account.account'].create({'name': 'Receivable', 'code': 'RCV00' , 'user_type_id': account_type_rcv.id, 'reconcile': True}) account_expense = self.env['account.account'].create({'name': 'Expense', 'code': 'EXP00' , 'user_type_id': account_type_oth.id, 'reconcile': True}) account_output = self.env['account.account'].create({'name': 'Output', 'code': 'OUT00' , 'user_type_id': account_type_oth.id, 'reconcile': True}) + account_valuation = self.env['account.account'].create({'name': 'Valuation', 'code': 'STV00', 'user_type_id': account_type_oth.id, 'reconcile': True}) self.partner.property_account_receivable_id = self.account self.category.property_account_income_categ_id = self.account self.category.property_account_expense_categ_id = account_expense self.category.property_stock_account_input_categ_id = self.account self.category.property_stock_account_output_categ_id = account_output - self.category.property_stock_valuation_account_id = self.account + self.category.property_stock_valuation_account_id = account_valuation self.category.property_stock_journal = self.env['account.journal'].create({'name': 'Stock journal', 'type': 'sale', 'code': 'STK00'}) self.pos_config = self.env.ref('point_of_sale.pos_config_main') self.pos_config = self.pos_config.copy({'name': 'New POS config'}) diff --git a/addons/sale_mrp/tests/test_sale_mrp_flow.py b/addons/sale_mrp/tests/test_sale_mrp_flow.py index 5e77a99ab45..51c18ca7283 100644 --- a/addons/sale_mrp/tests/test_sale_mrp_flow.py +++ b/addons/sale_mrp/tests/test_sale_mrp_flow.py @@ -405,12 +405,13 @@ class TestSaleMrpFlow(common.TransactionCase): self.account_receiv = self.env['account.account'].create({'name': 'Receivable', 'code': 'RCV00' , 'user_type_id': account_type.id, 'reconcile': True}) account_expense = self.env['account.account'].create({'name': 'Expense', 'code': 'EXP00' , 'user_type_id': account_type.id, 'reconcile': True}) account_output = self.env['account.account'].create({'name': 'Output', 'code': 'OUT00' , 'user_type_id': account_type.id, 'reconcile': True}) + account_valuation = self.env['account.account'].create({'name': 'Valuation', 'code': 'STV00' , 'user_type_id': account_type.id, 'reconcile': True}) self.partner.property_account_receivable_id = self.account_receiv self.category.property_account_income_categ_id = self.account_receiv self.category.property_account_expense_categ_id = account_expense self.category.property_stock_account_input_categ_id = self.account_receiv self.category.property_stock_account_output_categ_id = account_output - self.category.property_stock_valuation_account_id = self.account_receiv + self.category.property_stock_valuation_account_id = account_valuation self.category.property_stock_journal = self.env['account.journal'].create({'name': 'Stock journal', 'type': 'sale', 'code': 'STK00'}) Product = self.env['product.product'] diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index c8817b777ef..81fa093ccd5 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -5,7 +5,7 @@ from odoo import api, fields, models, tools, _ from odoo.exceptions import UserError from odoo.tools import float_is_zero, pycompat from odoo.addons import decimal_precision as dp - +from odoo.exceptions import ValidationError class ProductTemplate(models.Model): @@ -394,6 +394,15 @@ class ProductCategory(models.Model): domain=[('deprecated', '=', False)], help="When real-time inventory valuation is enabled on a product, this account will hold the current value of the products.",) + @api.constrains('property_stock_valuation_account_id', 'property_stock_account_output_categ_id', 'property_stock_account_input_categ_id') + def _check_valuation_accouts(self): + # Prevent to set the valuation account as the input or output account. + for category in self: + valuation_account = category.property_stock_valuation_account_id + input_and_output_accounts = category.property_stock_account_input_categ_id | category.property_stock_account_output_categ_id + if valuation_account and valuation_account in input_and_output_accounts: + raise ValidationError(_('The Stock Input and/or Output accounts cannot be the same than the Stock Valuation account.')) + @api.onchange('property_cost_method') def onchange_property_valuation(self): if not self._origin: