[FIX] sale_mrp: inherit MO analytic account from SO
Steps to reproduce: - Enable MTO - Create a manufactured product (no analytic distribution on the bom) - Create an SO for that product and set an analytic account on it - Confirm the SO Bug: no analytic account on the created MO Fix: inherit MO analytic account from SO if none is set on the BOM opw-3708134 closes odoo/odoo#156535 X-original-commit: cd72327ff3fb3633e353b7f9443ca973c358fc01 Signed-off-by: William Henrotin (whe) <whe@odoo.com> Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
@@ -9,6 +9,9 @@ class StockRule(models.Model):
|
||||
|
||||
def _prepare_mo_vals(self, product_id, product_qty, product_uom, location_id, name, origin, company_id, values, bom):
|
||||
res = super()._prepare_mo_vals(product_id, product_qty, product_uom, location_id, name, origin, company_id, values, bom)
|
||||
if not bom.analytic_distribution and values.get('analytic_distribution'):
|
||||
res['analytic_distribution'] = values.get('analytic_distribution')
|
||||
if not bom.analytic_distribution:
|
||||
if values.get('analytic_distribution'):
|
||||
res['analytic_distribution'] = values.get('analytic_distribution')
|
||||
elif values.get('analytic_account_id'):
|
||||
res['analytic_distribution'] = {values.get('analytic_account_id').id: 100}
|
||||
return res
|
||||
|
||||
@@ -10,6 +10,8 @@ class StockMove(models.Model):
|
||||
def _prepare_procurement_values(self):
|
||||
res = super()._prepare_procurement_values()
|
||||
res['analytic_account_id'] = self.sale_line_id.order_id.analytic_account_id
|
||||
if self.sale_line_id.order_id.analytic_account_id:
|
||||
res['analytic_distribution'] = {self.sale_line_id.order_id.analytic_account_id.id: 100}
|
||||
return res
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_sale_mrp_account
|
||||
from . import test_sale_mrp_flow
|
||||
from . import test_sale_mrp_kit_bom
|
||||
from . import test_sale_mrp_lead_time
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_multistep_manufacturing
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
@common.tagged('post_install', '-at_install')
|
||||
class TestSaleMrpAccount(test_multistep_manufacturing.TestMultistepManufacturing):
|
||||
def test_mo_analytic_distribution(self):
|
||||
""" ensure analytic account/distribution is inherited from the SO
|
||||
when none is set on the bom
|
||||
"""
|
||||
analytic_plan = self.env['account.analytic.plan'].create({
|
||||
'name': 'Plan',
|
||||
})
|
||||
self.sale_order.analytic_account_id = self.env['account.analytic.account'].create({
|
||||
'name': 'test_analytic_account',
|
||||
'plan_id': analytic_plan.id,
|
||||
})
|
||||
self.sale_order.action_confirm()
|
||||
self.assertTrue(self.sale_order.mrp_production_ids.analytic_distribution)
|
||||
self.assertTrue(self.sale_order.mrp_production_ids.analytic_account_ids)
|
||||
Reference in New Issue
Block a user