[ADD] mrp_account_bom_attribute_match

This commit is contained in:
Ivàn Todorovich
2023-01-31 10:32:24 -03:00
committed by Ilyas
parent 853bb4e7fa
commit 9359e6e2ce
11 changed files with 88 additions and 8 deletions

View File

@@ -0,0 +1 @@
TO BE GENERATED

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,16 @@
# Copyright 2023 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <ivan.todorovich@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "MRP Account BOM Attribute Match",
"summary": "Glue module between `mrp_account` and `mrp_bom_attribute_match`",
"version": "15.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["ivantodorovich"],
"website": "https://github.com/OCA/manufacture",
"license": "AGPL-3",
"category": "Manufacturing",
"depends": ["mrp_account", "mrp_bom_attribute_match"],
"auto_install": True,
}

View File

@@ -0,0 +1 @@
from . import product_product

View File

@@ -0,0 +1,34 @@
# Copyright 2023 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <ivan.todorovich@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import Command, models
class ProductProduct(models.Model):
_inherit = "product.product"
def _compute_bom_price(self, bom, boms_to_recompute=False, byproduct_bom=False):
# OVERRIDE to fill in the `line.product_id` if a component template is used.
# To avoid a complete override, we HACK the bom by replacing it with a virtual
# record, and modifying it's lines on-the-fly.
has_template_lines = bom and any(
line.component_template_id for line in bom.bom_line_ids
)
if has_template_lines:
bom = bom.new(origin=bom)
to_ignore_line_ids = []
for line in bom.bom_line_ids:
if line._skip_bom_line(self) or not line.component_template_id:
continue
line_product = bom._get_component_template_product(
line, self, line.product_id
)
if not line_product:
to_ignore_line_ids.append(line.id)
continue
else:
line.product_id = line_product
if to_ignore_line_ids:
bom.bom_line_ids = [Command.unlink(id) for id in to_ignore_line_ids]
return super()._compute_bom_price(bom, boms_to_recompute, byproduct_bom)

View File

@@ -0,0 +1 @@
from . import test_mrp_account_bom_attribute_match

View File

@@ -0,0 +1,23 @@
# Copyright 2023 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <ivan.todorovich@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.addons.mrp_bom_attribute_match.tests.common import (
TestMrpBomAttributeMatchBase,
)
class TestMrpAccount(TestMrpBomAttributeMatchBase):
@classmethod
def setUpClass(cls):
super().setUpClass()
def test_bom_cost(self):
sword_cyan, sword_magenta = self.product_sword.product_variant_ids
plastic_cyan, plastic_magenta = self.product_plastic.product_variant_ids
plastic_cyan.standard_price = 1.00
plastic_magenta.standard_price = 2.00
sword_cyan.button_bom_cost()
sword_magenta.button_bom_cost()
self.assertEqual(sword_cyan.standard_price, 1.00)
self.assertEqual(sword_magenta.standard_price, 2.00)

View File

@@ -1,7 +1,7 @@
from odoo.tests import Form, common
from odoo.tests import Form, TransactionCase
class TestMrpAttachmentMgmtBase(common.SavepointCase):
class TestMrpBomAttributeMatchBase(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()

View File

@@ -1,14 +1,10 @@
from odoo.exceptions import UserError, ValidationError
from odoo.tests import Form
from .common import TestMrpAttachmentMgmtBase
from .common import TestMrpBomAttributeMatchBase
class TestMrpAttachmentMgmt(TestMrpAttachmentMgmtBase):
@classmethod
def setUpClass(cls):
super().setUpClass()
class TestMrpAttachmentMgmt(TestMrpBomAttributeMatchBase):
def test_bom_1(self):
mrp_bom_form = Form(self.env["mrp.bom"])
mrp_bom_form.product_tmpl_id = self.product_sword

View File

@@ -0,0 +1 @@
../../../../mrp_account_bom_attribute_match

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)