Skip to content
Snippets Groups Projects
Commit 35e3af77 authored by Pieter Claeys (clpi)'s avatar Pieter Claeys (clpi)
Browse files

[FIX] mrp: Update analytic lines when changing account on MO

Upon changing/removing/adding the analytic account on a manufacturing order, only the analytic lines due to the raw material moves are updated, but not the ones for workcenter costs.

To reproduce:
- Create an MO with a workorder on a workcenter which has an operating cost set
- Complete time on this workorder to generate the [WC] AALs on this MO
- Change the analytic account on the MO (or delete it)
  Bug: The [WC] AALs never get correctly updated.

This fix builds on https://github.com/odoo/odoo/pull/79614 to correct this behaviour and also take into account changes for the workcenter cost AALs when the analytic_account of a manufacturing order is changed.

Community PR: https://github.com/odoo/odoo/pull/117308



closes odoo/odoo#121891

Task: 3252742
X-original-commit: cdf28628
Signed-off-by: default avatarArnold Moyaux (arm) <arm@odoo.com>
parent 440c0f04
No related branches found
No related tags found
No related merge requests found
......@@ -49,11 +49,14 @@ class MrpProduction(models.Model):
if vals['analytic_account_id'] and origin_analytic_account[production]:
# Link the account analytic lines to the new AA
production.move_raw_ids.analytic_account_line_id.write({'account_id': vals['analytic_account_id']})
production.workorder_ids.mo_analytic_account_line_id.write({'account_id': vals['analytic_account_id']})
elif vals['analytic_account_id'] and not origin_analytic_account[production]:
# Create the account analytic lines if no AA is set in the MO
production.move_raw_ids._account_analytic_entry_move()
production.workorder_ids._create_or_update_analytic_entry()
else:
production.move_raw_ids.analytic_account_line_id.unlink()
production.workorder_ids.mo_analytic_account_line_id.unlink()
return res
def action_view_stock_valuation_layers(self):
......
......@@ -207,6 +207,8 @@ class TestAnalyticAccount(TestMrpAnalyticAccount):
""" Check if the MO account analytic lines are correctly updated
after the change of the MO account analytic.
"""
# Required for `workorder_ids` to be visible in the view
self.env.user.groups_id += self.env.ref('mrp.group_mrp_routings')
# create a mo
mo_form = Form(self.env['mrp.production'])
mo_form.product_id = self.product
......@@ -217,6 +219,14 @@ class TestAnalyticAccount(TestMrpAnalyticAccount):
mo.action_confirm()
self.assertEqual(mo.state, 'confirmed')
self.assertEqual(len(mo.move_raw_ids.analytic_account_line_id), 0)
self.assertEqual(len(mo.workorder_ids.mo_analytic_account_line_id), 0)
# Change duration to 60
mo_form = Form(mo)
with mo_form.workorder_ids.edit(0) as line_edit:
line_edit.duration = 60.0
mo_form.save()
self.assertEqual(mo.workorder_ids.mo_analytic_account_line_id.account_id, self.analytic_account)
# Mark as done
wizard_dict = mo.button_mark_done()
......@@ -230,16 +240,21 @@ class TestAnalyticAccount(TestMrpAnalyticAccount):
# Change the MO analytic account
mo.analytic_account_id = new_analytic_account
self.assertEqual(mo.move_raw_ids.analytic_account_line_id.account_id.id, new_analytic_account.id)
self.assertEqual(mo.workorder_ids.mo_analytic_account_line_id.account_id.id, new_analytic_account.id)
#Get the MO analytic account lines
mo_analytic_account_lines = mo.move_raw_ids.analytic_account_line_id
mo_analytic_account_raw_lines = mo.move_raw_ids.analytic_account_line_id
mo_analytic_account_wc_lines = mo.workorder_ids.mo_analytic_account_line_id
mo.analytic_account_id = False
# Check that the MO analytic account lines are deleted
self.assertEqual(len(mo.move_raw_ids.analytic_account_line_id), 0)
self.assertFalse(mo_analytic_account_lines.exists())
self.assertEqual(len(mo.workorder_ids.mo_analytic_account_line_id), 0)
self.assertFalse(mo_analytic_account_raw_lines.exists())
self.assertFalse(mo_analytic_account_wc_lines.exists())
# Check that the AA lines are recreated correctly if we delete the AA, save the MO, and assign a new one
mo.analytic_account_id = self.analytic_account
self.assertEqual(len(mo.move_raw_ids.analytic_account_line_id), 1)
self.assertEqual(len(mo.workorder_ids.mo_analytic_account_line_id), 1)
def test_add_wo_analytic_no_company(self):
"""Test the addition of work orders to a MO linked to
......
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