diff --git a/addons/mrp_account/models/mrp_workorder.py b/addons/mrp_account/models/mrp_workorder.py index 5f2729f4ca4..be3792ac0aa 100644 --- a/addons/mrp_account/models/mrp_workorder.py +++ b/addons/mrp_account/models/mrp_workorder.py @@ -50,7 +50,8 @@ class MrpWorkorder(models.Model): mo_account = wo.production_id.analytic_account_id wc_account = wo.workcenter_id.costs_hour_account_id if mo_account: - is_zero = float_is_zero(value, precision_rounding=mo_account.currency_id.rounding) + mo_currency = mo_account.currency_id or wo.company_id.currency_id + is_zero = float_is_zero(value, precision_rounding=mo_currency.rounding) if wo.mo_analytic_account_line_id: wo.mo_analytic_account_line_id.write({ 'unit_amount': hours, diff --git a/addons/mrp_account/tests/test_analytic_account.py b/addons/mrp_account/tests/test_analytic_account.py index 82295ac8364..f05b535a349 100644 --- a/addons/mrp_account/tests/test_analytic_account.py +++ b/addons/mrp_account/tests/test_analytic_account.py @@ -245,3 +245,31 @@ class TestAnalyticAccount(TestMrpAnalyticAccount): # 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) + + def test_add_wo_analytic_no_company(self): + """Test the addition of work orders to a MO linked to + an analytic account that has no company associated + """ + # Create an analytic account and remove the company + analytic_account_no_company = self.env['account.analytic.account'].create({ + 'name': 'test_analytic_account_no_company', + 'plan_id': self.analytic_plan.id, + }) + analytic_account_no_company.company_id = False + + # Create a mo linked to an analytic account with no associated company + mo_no_company = self.env['mrp.production'].create({ + 'product_id': self.product.id, + 'analytic_account_id': analytic_account_no_company.id, + 'product_uom_id': self.bom.product_uom_id.id, + }) + + mo_no_c_form = Form(mo_no_company) + self.env['mrp.workorder'].create({ + 'name': 'Work_order', + 'workcenter_id': self.workcenter.id, + 'product_uom_id': self.bom.product_uom_id.id, + 'production_id': mo_no_c_form.id, + }) + mo_no_c_form.save() + self.assertTrue(mo_no_company.workorder_ids)