diff --git a/addons/mrp_account/models/mrp_production.py b/addons/mrp_account/models/mrp_production.py index 31fb122e9b9f5d258583faa9ce9cd5b68a054ff1..0b0fd3901011a18ad9840889c5bd76f710a2c965 100644 --- a/addons/mrp_account/models/mrp_production.py +++ b/addons/mrp_account/models/mrp_production.py @@ -46,11 +46,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): diff --git a/addons/mrp_account/tests/test_analytic_account.py b/addons/mrp_account/tests/test_analytic_account.py index dbf80907be9e511f6c4d2d40311af7c0f706aa42..1f3acf71a1de4cca3271f18b8cbbcb6af4958c5e 100644 --- a/addons/mrp_account/tests/test_analytic_account.py +++ b/addons/mrp_account/tests/test_analytic_account.py @@ -202,6 +202,13 @@ class TestAnalyticAccount(TransactionCase): 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 + 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() @@ -214,16 +221,21 @@ class TestAnalyticAccount(TransactionCase): # 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