[FIX] stock_account: retain assigned automated accounts

Steps to reproduce:
1- install stock_account and account_accountant
2- activate in Settings > Accounting > Automatic Accounting
3- open a Product Category > set Inventory Valuation = Automated
   [`real_time`] (optional step: can change the account stock properties
   values, but doesn't matter)
4- install mrp_account

Expected result:
- Accounts already set under the Account Stock Properties
  (i.e.: property_stock_valuation_account_id,
         property_stock_account_input_categ_id, etc)
  remain unchanged.

Actual result:
- Account stock properties for any Product Categories already set to
  Automated before installing mrp_account are wiped to nothing

Issue:
`_post_load_data` was resetting all property values (i.e. the accounts)
to False since PR odoo/odoo#119564 to ensure correct accounts were used
for `manual_periodic` valuation when stock_account and mrp_account are
first installed. This was previously not an issue because no valuations
could be set to `real_time` before stock_account was installed and
mrp_account did not run `post_load_data` (i.e. an mrp account was added)
until saas-16.3. So now we avoid wiping existing assigned accounts when
mrp_account calls `_post_load_data` at its install time

closes odoo/odoo#147958

Task: 3471065
X-original-commit: cc741525f9349077aefc7d137b6199a68fc87a23
Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
This commit is contained in:
Tiffany Chang (tic)
2024-01-17 15:36:29 +00:00
parent 4a7b2a5051
commit f7b36faf54
2 changed files with 12 additions and 5 deletions
@@ -11,9 +11,16 @@ class AccountChartTemplate(models.AbstractModel):
def _post_load_data(self, template_code, company, template_data):
super()._post_load_data(template_code, company, template_data)
company = company or self.env.company
categ_values = {category.id: False for category in self.env['product.category'].search([])}
for fname in self.env['product.category']._get_stock_account_property_field_names():
self.env['ir.property'].with_company(company.id)._set_multi(fname, 'product.category', categ_values, True)
fields_name = self.env['product.category']._get_stock_account_property_field_names()
account_fields = self.env['ir.model.fields'].search([('model', '=', 'product.category'), ('name', 'in', fields_name)])
existing_props = self.env['ir.property'].sudo().search([
('fields_id', 'in', account_fields.ids),
('company_id', '=', company.id),
('res_id', '!=', False),
])
for fname in fields_name:
if fname in existing_props.mapped('fields_id.name'):
continue
value = template_data.get(fname)
if value:
self.env['ir.property']._set_default(fname, 'product.category', self.ref(value).id, company=company)
+2 -2
View File
@@ -856,7 +856,7 @@ class ProductCategory(models.Model):
account_moves._post()
return res
# delete in master
@api.onchange('property_valuation')
def onchange_property_valuation(self):
# Remove or set the account stock properties if necessary
self._check_valuation_accounts()
pass