mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[ADD] mrp_account_bom_attribute_match
This commit is contained in:
1
mrp_account_bom_attribute_match/README.rst
Normal file
1
mrp_account_bom_attribute_match/README.rst
Normal file
@@ -0,0 +1 @@
|
||||
TO BE GENERATED
|
||||
1
mrp_account_bom_attribute_match/__init__.py
Normal file
1
mrp_account_bom_attribute_match/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
16
mrp_account_bom_attribute_match/__manifest__.py
Normal file
16
mrp_account_bom_attribute_match/__manifest__.py
Normal 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,
|
||||
}
|
||||
1
mrp_account_bom_attribute_match/models/__init__.py
Normal file
1
mrp_account_bom_attribute_match/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import product_product
|
||||
34
mrp_account_bom_attribute_match/models/product_product.py
Normal file
34
mrp_account_bom_attribute_match/models/product_product.py
Normal 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)
|
||||
1
mrp_account_bom_attribute_match/tests/__init__.py
Normal file
1
mrp_account_bom_attribute_match/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_mrp_account_bom_attribute_match
|
||||
@@ -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)
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
../../../../mrp_account_bom_attribute_match
|
||||
6
setup/mrp_account_bom_attribute_match/setup.py
Normal file
6
setup/mrp_account_bom_attribute_match/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
Reference in New Issue
Block a user