Skip to content

Commit

Permalink
[FIX] stock_account: retain assigned automated accounts
Browse files Browse the repository at this point in the history
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#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#147958

Task: 3471065
X-original-commit: cc74152
Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
  • Loading branch information
ticodoo committed Jan 17, 2024
1 parent 4a7b2a5 commit f7b36fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions addons/stock_account/models/account_chart_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions addons/stock_account/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ def write(self, vals):
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

0 comments on commit f7b36fa

Please sign in to comment.