mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] mrp_bom_attribute_match: increase test strength: add another component to bom
This commit is contained in:
@@ -1 +1,83 @@
|
||||
TO BE GENERATED
|
||||
===============================
|
||||
MRP Account BOM Attribute Match
|
||||
===============================
|
||||
|
||||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
|
||||
:target: https://odoo-community.org/page/development-status
|
||||
:alt: Beta
|
||||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github
|
||||
:target: https://github.com/OCA/manufacture/tree/15.0/mrp_account_bom_attribute_match
|
||||
:alt: OCA/manufacture
|
||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||
:target: https://translation.odoo-community.org/projects/manufacture-15-0/manufacture-15-0-mrp_account_bom_attribute_match
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
|
||||
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/manufacture&target_branch=15.0
|
||||
:alt: Try me on Runboat
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
Glue module between `mrp_bom_attribute_match` and `mrp_account`.
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/manufacture/issues>`_.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
`feedback <https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_account_bom_attribute_match%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Do not contact contributors directly about support or help with technical issues.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Authors
|
||||
~~~~~~~
|
||||
|
||||
* Camptocamp
|
||||
|
||||
Contributors
|
||||
~~~~~~~~~~~~
|
||||
|
||||
* `Camptocamp <https://www.camptocamp.com>`_
|
||||
|
||||
* Iván Todorovich <ivan.todorovich@camptocamp.com>
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
.. image:: https://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: https://odoo-community.org
|
||||
|
||||
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
.. |maintainer-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px
|
||||
:target: https://github.com/ivantodorovich
|
||||
:alt: ivantodorovich
|
||||
|
||||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|
||||
|
||||
|maintainer-ivantodorovich|
|
||||
|
||||
This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/15.0/mrp_account_bom_attribute_match>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
{
|
||||
"name": "MRP Account BOM Attribute Match",
|
||||
"summary": "Glue module between `mrp_account` and `mrp_bom_attribute_match`",
|
||||
"version": "15.0.1.0.0",
|
||||
"version": "14.0.1.0.0",
|
||||
"author": "Camptocamp, Odoo Community Association (OCA)",
|
||||
"maintainers": ["ivantodorovich"],
|
||||
"website": "https://github.com/OCA/manufacture",
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
# @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
|
||||
from odoo import models
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = "product.product"
|
||||
|
||||
def _compute_bom_price(self, bom, boms_to_recompute=False, byproduct_bom=False):
|
||||
def _compute_bom_price(self, bom, boms_to_recompute=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.
|
||||
@@ -30,5 +30,6 @@ class ProductProduct(models.Model):
|
||||
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)
|
||||
for to_ignore_line_id in to_ignore_line_ids:
|
||||
bom.bom_line_ids = [(3, to_ignore_line_id, 0)]
|
||||
return super()._compute_bom_price(bom, boms_to_recompute)
|
||||
|
||||
8
mrp_account_bom_attribute_match/readme/CONTRIBUTORS.rst
Normal file
8
mrp_account_bom_attribute_match/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1,8 @@
|
||||
* `Camptocamp <https://www.camptocamp.com>`_
|
||||
|
||||
* Iván Todorovich <ivan.todorovich@camptocamp.com>
|
||||
|
||||
|
||||
* `Ooops404 <https://ooops404.com>`_
|
||||
|
||||
* Ilyas <irazor147@gmail.com>
|
||||
0
mrp_account_bom_attribute_match/readme/USAGE.rst
Normal file
0
mrp_account_bom_attribute_match/readme/USAGE.rst
Normal file
BIN
mrp_account_bom_attribute_match/static/description/icon.png
Normal file
BIN
mrp_account_bom_attribute_match/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
@@ -1 +1,2 @@
|
||||
from . import common
|
||||
from . import test_mrp_account_bom_attribute_match
|
||||
|
||||
171
mrp_account_bom_attribute_match/tests/common.py
Normal file
171
mrp_account_bom_attribute_match/tests/common.py
Normal file
@@ -0,0 +1,171 @@
|
||||
from odoo.models import BaseModel
|
||||
from odoo.tests import Form, SavepointCase
|
||||
|
||||
|
||||
class TestMrpBomAttributeMatchBase(SavepointCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
||||
cls.warehouse = cls.env.ref("stock.warehouse0")
|
||||
cls.route_manufacture = cls.warehouse.manufacture_pull_id.route_id
|
||||
# Create products
|
||||
cls.product_sword = cls.env["product.template"].create(
|
||||
{
|
||||
"name": "Plastic Sword",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
cls.product_surf = cls.env["product.template"].create(
|
||||
{
|
||||
"name": "Surf",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
cls.product_fin = cls.env["product.template"].create(
|
||||
{
|
||||
"name": "Surf Fin",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
cls.product_plastic = cls.env["product.template"].create(
|
||||
{
|
||||
"name": "Plastic Component",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
cls.p1 = cls.env["product.template"].create(
|
||||
{
|
||||
"name": "P1",
|
||||
"type": "product",
|
||||
"route_ids": [(4, cls.route_manufacture.id, 0)],
|
||||
}
|
||||
)
|
||||
cls.p2 = cls.env["product.template"].create(
|
||||
{
|
||||
"name": "P2",
|
||||
"type": "product",
|
||||
"route_ids": [(4, cls.route_manufacture.id, 0)],
|
||||
}
|
||||
)
|
||||
cls.p3 = cls.env["product.template"].create(
|
||||
{
|
||||
"name": "P3",
|
||||
"type": "product",
|
||||
"route_ids": [(4, cls.route_manufacture.id, 0)],
|
||||
}
|
||||
)
|
||||
cls.product_9 = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "Paper",
|
||||
}
|
||||
)
|
||||
cls.product_10 = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "Stone",
|
||||
}
|
||||
)
|
||||
cls.product_attribute = cls.env["product.attribute"].create(
|
||||
{"name": "Colour", "display_type": "radio", "create_variant": "always"}
|
||||
)
|
||||
cls.attribute_value_ids = cls.env["product.attribute.value"].create(
|
||||
[
|
||||
{"name": "Cyan", "attribute_id": cls.product_attribute.id},
|
||||
{"name": "Magenta", "attribute_id": cls.product_attribute.id},
|
||||
]
|
||||
)
|
||||
cls.plastic_attrs = cls.env["product.template.attribute.line"].create(
|
||||
{
|
||||
"attribute_id": cls.product_attribute.id,
|
||||
"product_tmpl_id": cls.product_plastic.id,
|
||||
"value_ids": [(6, 0, cls.product_attribute.value_ids.ids)],
|
||||
}
|
||||
)
|
||||
cls.sword_attrs = cls.env["product.template.attribute.line"].create(
|
||||
{
|
||||
"attribute_id": cls.product_attribute.id,
|
||||
"product_tmpl_id": cls.product_sword.id,
|
||||
"value_ids": [(6, 0, cls.product_attribute.value_ids.ids)],
|
||||
}
|
||||
)
|
||||
# Create boms
|
||||
cls.bom_id = cls._create_bom(
|
||||
cls.product_sword,
|
||||
[
|
||||
dict(
|
||||
component_template_id=cls.product_plastic.id,
|
||||
product_qty=1,
|
||||
),
|
||||
dict(
|
||||
product_id=cls.product_9,
|
||||
product_qty=1,
|
||||
),
|
||||
],
|
||||
)
|
||||
cls.fin_bom_id = cls._create_bom(
|
||||
cls.product_fin,
|
||||
[
|
||||
dict(
|
||||
product_id=cls.product_plastic.product_variant_ids[0],
|
||||
product_qty=1,
|
||||
),
|
||||
],
|
||||
)
|
||||
cls.surf_bom_id = cls._create_bom(
|
||||
cls.product_surf,
|
||||
[
|
||||
dict(
|
||||
product_id=cls.product_fin.product_variant_ids[0],
|
||||
product_qty=1,
|
||||
),
|
||||
],
|
||||
)
|
||||
cls.p1_bom_id = cls._create_bom(
|
||||
cls.p1,
|
||||
[
|
||||
dict(
|
||||
product_id=cls.p2.product_variant_ids[0],
|
||||
product_qty=1,
|
||||
),
|
||||
],
|
||||
)
|
||||
cls.p2_bom_id = cls._create_bom(
|
||||
cls.p2,
|
||||
[
|
||||
dict(
|
||||
product_id=cls.p3.product_variant_ids[0],
|
||||
product_qty=1,
|
||||
),
|
||||
],
|
||||
)
|
||||
cls.p3_bom_id = cls._create_bom(
|
||||
cls.p3,
|
||||
[
|
||||
dict(
|
||||
product_id=cls.p1.product_variant_ids[0],
|
||||
product_qty=1,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _create_bom(cls, product, line_form_vals):
|
||||
if product._name == "product.template":
|
||||
template = product
|
||||
product = cls.env["product.product"]
|
||||
else:
|
||||
template = product.product_tmpl_id
|
||||
with Form(cls.env["mrp.bom"]) as form:
|
||||
form.product_tmpl_id = template
|
||||
form.product_id = product
|
||||
for vals in line_form_vals:
|
||||
with form.bom_line_ids.new() as line_form:
|
||||
for key, value in vals.items():
|
||||
field = line_form._model._fields.get(key)
|
||||
if field and field.relational: # pragma: no cover
|
||||
if value and not isinstance(value, BaseModel):
|
||||
value = cls.env[field.comodel_name].browse(value)
|
||||
elif not value:
|
||||
value = cls.env[field.comodel_name]
|
||||
setattr(line_form, key, value)
|
||||
return form.save()
|
||||
@@ -2,9 +2,7 @@
|
||||
# @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,
|
||||
)
|
||||
from .common import TestMrpBomAttributeMatchBase
|
||||
|
||||
|
||||
class TestMrpAccount(TestMrpBomAttributeMatchBase):
|
||||
|
||||
Reference in New Issue
Block a user