[FIX] mrp_account: no currency in analytics
Current behaviour: Cannot add a Work Order to a Manufacturing Order if the analytic account linked to the MO doesn't have an associated company. Expected behaviour: Should be able to add a WO to a MO even if the linked analytic account doesn't have an associated company. Steps to reproduce: 1. Activate analytic accounts 2. Activate work orders 3. Create an analytic account without company associated 4. Create a Manufacturing Order 5. In miscellaneous, link the analytic account 6. Try to add a WO line 7. Error log Reason for the problem: When trying to add a WO line, if the MO has been linked to an analytic account, it checks for the currency in the company in the analytic account, which was not existent, since the company didn't exist. Fix: When trying to access currency, if the company in the analytic account doesn't exist, it defaults to the company in the WO. opw-3210708 closes odoo/odoo#117708 X-original-commit: f0d8f5e82e62e0bcfc05e25dac2504f8f07537f4 Signed-off-by: Demany Antoine (ande) <ande@odoo.com> Signed-off-by: Tiffany Chang <tic@odoo.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user