[IMP]stock_account: Prevent user to set same valuation account and IN/OUT accounts.

In this commit use the python constraint to check the accounts if they are duplicate.

This change is because before this configuration there will be an entry cancelling another one in the same account,
resulting in a not impacted valuation account.

This commit is related to task #1908065.

closes odoo/odoo#28604
This commit is contained in:
Pratima Gupta
2018-11-27 07:23:15 +00:00
parent cca864f509
commit 5a2b38918a
3 changed files with 14 additions and 3 deletions
@@ -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'})
+2 -1
View File
@@ -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']
+10 -1
View File
@@ -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: