Skip to content
Snippets Groups Projects
Commit 10b86acd authored by Adrien Widart (awt)'s avatar Adrien Widart (awt)
Browse files

[FIX] {stock,mrp}_account,stock_landed_costs: set product categories properties

[1] is not enough. First, when installing `stock_account`, the
post-install hook will only add `False` values to the first company.
We should do it for all existing ones

Second, the field `property_valuation` is company-dependent:
https://github.com/odoo/odoo/blob/640907ec1852c4e477957c865549a87d3ae840dd/addons/stock_account/models/product.py#L708-L714
And when creating a new company, its value will be (by default)
`manual_periodic`. Therefore, the other properties should also be
set to `False`.

Note about test modification: for the tests in `stock_landed_costs`
module, we set the categ to auto so the stock accounts are defined.
Otherwise, when validating the landed costs, it will lead to an error
https://github.com/odoo/odoo/blob/608ed487b61c81e38a5d0b856732a8b94c6df64a/addons/stock_landed_costs/models/stock_landed_cost.py#L416-L417

[1] 9dc7835c

OPW-2746384

Part-of: odoo/odoo#119104
parent 6db128f7
No related branches found
No related tags found
No related merge requests found
......@@ -200,7 +200,7 @@ class TestMrpAccountMove(TestAccountMoveStockCommon):
"name": "Product B",
"type": "product",
"default_code": "prda",
"categ_id": cls.env.ref("product.product_category_all").id,
"categ_id": cls.auto_categ.id,
"taxes_id": [(5, 0, 0)],
"supplier_taxes_id": [(5, 0, 0)],
"lst_price": 100.0,
......
......@@ -20,6 +20,7 @@ def _configure_journals(cr, registry):
'property_stock_valuation_account_id',
]
# Property Stock Accounts
categ_values = {category.id: False for category in env['product.category'].search([])}
for company_id in company_ids:
# Check if property exists for stock account journal exists
field = env['ir.model.fields']._get("product.category", "property_stock_journal")
......@@ -57,10 +58,4 @@ def _configure_journals(cr, registry):
account,
company_id,
)
for name in todo_list:
env['ir.property']._set_multi(
name,
'product.category',
{category.id: False for category in env['product.category'].search([])},
True
)
env['ir.property'].with_company(company_id.id)._set_multi(name, 'product.category', categ_values, True)
......@@ -27,9 +27,11 @@ class AccountChartTemplate(models.Model):
'property_stock_account_output_categ_id',
'property_stock_valuation_account_id',
]
categ_values = {category.id: False for category in self.env['product.category'].search([])}
for field in todo_list:
account = self[field]
value = acc_template_ref[account].id if account else False
PropertyObj._set_default(field, "product.category", value, company)
PropertyObj._set_multi(field, "product.category", categ_values, True)
return res
......@@ -19,12 +19,25 @@ class TestAccountMoveStockCommon(AccountTestInvoicingCommon):
cls.stock_journal,
) = _create_accounting_data(cls.env)
# `all_categ` should not be altered, so we can test the `post_init` hook of `stock_account`
cls.all_categ = cls.env.ref('product.product_category_all')
cls.auto_categ = cls.env['product.category'].create({
'name': 'child_category',
'parent_id': cls.all_categ.id,
"property_stock_account_input_categ_id": cls.stock_input_account.id,
"property_stock_account_output_categ_id": cls.stock_output_account.id,
"property_stock_valuation_account_id": cls.stock_valuation_account.id,
"property_stock_journal": cls.stock_journal.id,
"property_valuation": "real_time",
"property_cost_method": "standard",
})
cls.product_A = cls.env["product.product"].create(
{
"name": "Product A",
"type": "product",
"default_code": "prda",
"categ_id": cls.env.ref("product.product_category_all").id,
"categ_id": cls.auto_categ.id,
"taxes_id": [(5, 0, 0)],
"supplier_taxes_id": [(5, 0, 0)],
"lst_price": 100.0,
......@@ -33,16 +46,6 @@ class TestAccountMoveStockCommon(AccountTestInvoicingCommon):
"property_account_expense_id": cls.company_data["default_account_expense"].id,
}
)
cls.product_A.categ_id.write(
{
"property_stock_account_input_categ_id": cls.stock_input_account.id,
"property_stock_account_output_categ_id": cls.stock_output_account.id,
"property_stock_valuation_account_id": cls.stock_valuation_account.id,
"property_stock_journal": cls.stock_journal.id,
"property_valuation": "real_time",
"property_cost_method": "standard",
}
)
@tagged("post_install", "-at_install")
......@@ -194,3 +197,33 @@ class TestAccountMove(TestAccountMoveStockCommon):
self.assertEqual(invoice.amount_total, 114)
self.assertEqual(invoice.amount_untaxed, 100)
self.assertEqual(invoice.amount_tax, 14)
def test_basic_bill(self):
"""
When billing a storable product with a basic category (manual
valuation), the account used should be the expenses one. This test
checks the flow with two companies:
- One that existed before the installation of `stock_account` (to test
the post-install hook)
- One created after the module installation
"""
first_company = self.env['res.company'].browse(1)
self.env.user.company_ids |= first_company
basic_product = self.env['product.product'].create({
'name': 'SuperProduct',
'type': 'product',
'categ_id': self.all_categ.id,
})
for company in (self.env.company | first_company):
bill_form = Form(self.env['account.move'].with_company(company.id).with_context(default_move_type='in_invoice'))
bill_form.partner_id = self.partner_a
bill_form.invoice_date = fields.Date.today()
with bill_form.invoice_line_ids.new() as line:
line.product_id = basic_product
line.price_unit = 100
bill = bill_form.save()
bill.action_post()
product_accounts = basic_product.product_tmpl_id.with_company(company.id).get_product_accounts()
self.assertEqual(bill.invoice_line_ids.account_id, product_accounts['expense'])
......@@ -70,6 +70,8 @@ class TestLandedCosts(TestStockLandedCostsCommon):
# 3.transportation 250 By Weight
# 4.packaging 20 By Volume
self.landed_cost.categ_id.property_valuation = 'real_time'
# Process incoming shipment
income_ship = self._process_incoming_shipment()
# Create landed costs
......@@ -196,6 +198,8 @@ class TestLandedCosts(TestStockLandedCostsCommon):
# 3.transportation -50 By Weight
# 4.packaging -5 By Volume
self.landed_cost.categ_id.property_valuation = 'real_time'
# Process incoming shipment
income_ship = self._process_incoming_shipment()
# Refrigerator outgoing shipment.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment