[FIX] mrp_account_bom_attribute_match: missing readme

This commit is contained in:
Ivàn Todorovich
2023-02-22 09:22:18 -03:00
committed by Ilyas
parent 522fa98d29
commit 88310db1de
10 changed files with 604 additions and 149 deletions

View File

@@ -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.

View File

@@ -5,7 +5,7 @@
{ {
"name": "MRP Account BOM Attribute Match", "name": "MRP Account BOM Attribute Match",
"summary": "Glue module between `mrp_account` and `mrp_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)", "author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["ivantodorovich"], "maintainers": ["ivantodorovich"],
"website": "https://github.com/OCA/manufacture", "website": "https://github.com/OCA/manufacture",

View File

@@ -2,13 +2,13 @@
# @author Iván Todorovich <ivan.todorovich@camptocamp.com> # @author Iván Todorovich <ivan.todorovich@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # 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): class ProductProduct(models.Model):
_inherit = "product.product" _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. # 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 # To avoid a complete override, we HACK the bom by replacing it with a virtual
# record, and modifying it's lines on-the-fly. # record, and modifying it's lines on-the-fly.
@@ -30,5 +30,6 @@ class ProductProduct(models.Model):
else: else:
line.product_id = line_product line.product_id = line_product
if to_ignore_line_ids: if to_ignore_line_ids:
bom.bom_line_ids = [Command.unlink(id) for id in to_ignore_line_ids] for to_ignore_line_id in to_ignore_line_ids:
return super()._compute_bom_price(bom, boms_to_recompute, byproduct_bom) bom.bom_line_ids = [(3, to_ignore_line_id, 0)]
return super()._compute_bom_price(bom, boms_to_recompute)

View File

@@ -0,0 +1 @@
Glue module between `mrp_bom_attribute_match` and `mrp_account`.

View File

@@ -0,0 +1,424 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>MRP Account BOM Attribute Match</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="mrp-account-bom-attribute-match">
<h1 class="title">MRP Account BOM Attribute Match</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/manufacture/tree/15.0/mrp_account_bom_attribute_match"><img alt="OCA/manufacture" src="https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/manufacture-15-0/manufacture-15-0-mrp_account_bom_attribute_match"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/webui/builds.html?repo=OCA/manufacture&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Glue module between <cite>mrp_bom_attribute_match</cite> and <cite>mrp_account</cite>.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#bug-tracker" id="id1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id5">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/manufacture/issues">GitHub Issues</a>.
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
<a class="reference external" href="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**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id2">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id3">Authors</a></h2>
<ul class="simple">
<li>Camptocamp</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id4">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.camptocamp.com">Camptocamp</a><ul>
<li>Iván Todorovich &lt;<a class="reference external" href="mailto:ivan.todorovich&#64;camptocamp.com">ivan.todorovich&#64;camptocamp.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/ivantodorovich"><img alt="ivantodorovich" src="https://github.com/ivantodorovich.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/manufacture/tree/15.0/mrp_account_bom_attribute_match">OCA/manufacture</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

View File

@@ -1 +1,2 @@
from . import common
from . import test_mrp_account_bom_attribute_match from . import test_mrp_account_bom_attribute_match

View File

@@ -2,9 +2,7 @@
# @author Iván Todorovich <ivan.todorovich@camptocamp.com> # @author Iván Todorovich <ivan.todorovich@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.addons.mrp_bom_attribute_match.tests.common import ( from .common import TestMrpBomAttributeMatchBase
TestMrpBomAttributeMatchBase,
)
class TestMrpAccount(TestMrpBomAttributeMatchBase): class TestMrpAccount(TestMrpBomAttributeMatchBase):

View File

@@ -2,7 +2,7 @@
# @author Iván Todorovich <ivan.todorovich@camptocamp.com> # @author Iván Todorovich <ivan.todorovich@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import Command, models from odoo import models
class ReportBomStructure(models.AbstractModel): class ReportBomStructure(models.AbstractModel):
@@ -30,7 +30,8 @@ class ReportBomStructure(models.AbstractModel):
else: else:
line.product_id = line_product line.product_id = line_product
if to_ignore_line_ids: if to_ignore_line_ids:
bom.bom_line_ids = [Command.unlink(id) for id in to_ignore_line_ids] for to_ignore_line_id in to_ignore_line_ids:
bom.bom_line_ids = [(3, to_ignore_line_id, 0)]
components, total = super()._get_bom_lines( components, total = super()._get_bom_lines(
bom, bom_quantity, product, line_id, level bom, bom_quantity, product, line_id, level
) )

View File

@@ -1,172 +1,134 @@
from odoo import Command from odoo.tests import Form, common
from odoo.models import BaseModel
from odoo.tests import Form, TransactionCase
class TestMrpBomAttributeMatchBase(TransactionCase): class TestMrpAttachmentMgmtBase(common.SavepointCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) cls._create_products(cls)
cls.warehouse = cls.env.ref("stock.warehouse0") cls._create_boms(cls)
cls.route_manufacture = cls.warehouse.manufacture_pull_id.route_id
# Create products def _create_products(self):
cls.product_sword = cls.env["product.template"].create( self.warehouse = self.env.ref("stock.warehouse0")
route_manufacture = self.warehouse.manufacture_pull_id.route_id.id
self.product_sword = self.env["product.template"].create(
{ {
"name": "Plastic Sword", "name": "Plastic Sword",
"type": "product", "type": "product",
} }
) )
cls.product_surf = cls.env["product.template"].create( self.product_surf = self.env["product.template"].create(
{ {
"name": "Surf", "name": "Surf",
"type": "product", "type": "product",
} }
) )
cls.product_fin = cls.env["product.template"].create( self.product_fin = self.env["product.template"].create(
{ {
"name": "Surf Fin", "name": "Surf Fin",
"type": "product", "type": "product",
} }
) )
cls.product_plastic = cls.env["product.template"].create( self.product_plastic = self.env["product.template"].create(
{ {
"name": "Plastic Component", "name": "Plastic Component",
"type": "product", "type": "product",
} }
) )
cls.p1 = cls.env["product.template"].create( self.p1 = self.env["product.template"].create(
{ {
"name": "P1", "name": "P1",
"type": "product", "type": "product",
"route_ids": [Command.link(cls.route_manufacture.id)], "route_ids": [(6, 0, [route_manufacture])],
} }
) )
cls.p2 = cls.env["product.template"].create( self.p2 = self.env["product.template"].create(
{ {
"name": "P2", "name": "P2",
"type": "product", "type": "product",
"route_ids": [Command.link(cls.route_manufacture.id)], "route_ids": [(6, 0, [route_manufacture])],
} }
) )
cls.p3 = cls.env["product.template"].create( self.p3 = self.env["product.template"].create(
{ {
"name": "P3", "name": "P3",
"type": "product", "type": "product",
"route_ids": [Command.link(cls.route_manufacture.id)], "route_ids": [(6, 0, [route_manufacture])],
} }
) )
cls.product_9 = cls.env["product.product"].create( self.product_9 = self.env["product.product"].create(
{ {
"name": "Paper", "name": "Paper",
} }
) )
cls.product_10 = cls.env["product.product"].create( self.product_10 = self.env["product.product"].create(
{ {
"name": "Stone", "name": "Stone",
} }
) )
cls.product_attribute = cls.env["product.attribute"].create( self.product_attribute = self.env["product.attribute"].create(
{"name": "Colour", "display_type": "radio", "create_variant": "always"} {"name": "Colour", "display_type": "radio", "create_variant": "always"}
) )
cls.attribute_value_ids = cls.env["product.attribute.value"].create( self.attribute_value_ids = self.env["product.attribute.value"].create(
[ [
{"name": "Cyan", "attribute_id": cls.product_attribute.id}, {"name": "Cyan", "attribute_id": self.product_attribute.id},
{"name": "Magenta", "attribute_id": cls.product_attribute.id}, {"name": "Magenta", "attribute_id": self.product_attribute.id},
] ]
) )
cls.plastic_attrs = cls.env["product.template.attribute.line"].create( self.plastic_attrs = self.env["product.template.attribute.line"].create(
{ {
"attribute_id": cls.product_attribute.id, "attribute_id": self.product_attribute.id,
"product_tmpl_id": cls.product_plastic.id, "product_tmpl_id": self.product_plastic.id,
"value_ids": [Command.set(cls.product_attribute.value_ids.ids)], "value_ids": [(6, 0, self.product_attribute.value_ids.ids)],
} }
) )
cls.sword_attrs = cls.env["product.template.attribute.line"].create( self.sword_attrs = self.env["product.template.attribute.line"].create(
{ {
"attribute_id": cls.product_attribute.id, "attribute_id": self.product_attribute.id,
"product_tmpl_id": cls.product_sword.id, "product_tmpl_id": self.product_sword.id,
"value_ids": [Command.set(cls.product_attribute.value_ids.ids)], "value_ids": [(6, 0, self.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_boms(self):
def _create_bom(cls, product, line_form_vals): mrp_bom_form = Form(self.env["mrp.bom"])
if product._name == "product.template": mrp_bom_form.product_tmpl_id = self.product_sword
template = product with mrp_bom_form.bom_line_ids.new() as line_form:
product = cls.env["product.product"] line_form.component_template_id = self.product_plastic
else: line_form.product_qty = 1
template = product.product_tmpl_id self.bom_id = mrp_bom_form.save()
with Form(cls.env["mrp.bom"]) as form:
form.product_tmpl_id = template mrp_bom_form = Form(self.env["mrp.bom"])
form.product_id = product mrp_bom_form.product_tmpl_id = self.product_fin
for vals in line_form_vals: with mrp_bom_form.bom_line_ids.new() as line_form:
with form.bom_line_ids.new() as line_form: line_form.product_id = self.product_plastic.product_variant_ids[0]
for key, value in vals.items(): line_form.product_qty = 1
field = line_form._model._fields.get(key) self.fin_bom_id = mrp_bom_form.save()
if field and field.relational: # pragma: no cover
if value and not isinstance(value, BaseModel): mrp_bom_form = Form(self.env["mrp.bom"])
value = cls.env[field.comodel_name].browse(value) mrp_bom_form.product_tmpl_id = self.product_surf
elif not value: with mrp_bom_form.bom_line_ids.new() as line_form:
value = cls.env[field.comodel_name] line_form.product_id = self.product_fin.product_variant_ids[0]
setattr(line_form, key, value) line_form.product_qty = 1
return form.save() self.surf_bom_id = mrp_bom_form.save()
mrp_bom_form = Form(self.env["mrp.bom"])
mrp_bom_form.product_tmpl_id = self.p1
with mrp_bom_form.bom_line_ids.new() as line_form:
line_form.product_id = self.p2.product_variant_ids[0]
line_form.product_qty = 1
self.p1_bom_id = mrp_bom_form.save()
mrp_bom_form = Form(self.env["mrp.bom"])
mrp_bom_form.product_tmpl_id = self.p2
with mrp_bom_form.bom_line_ids.new() as line_form:
line_form.product_id = self.p3.product_variant_ids[0]
line_form.product_qty = 1
self.p2_bom_id = mrp_bom_form.save()
mrp_bom_form = Form(self.env["mrp.bom"])
mrp_bom_form.product_tmpl_id = self.p3
with mrp_bom_form.bom_line_ids.new() as line_form:
line_form.product_id = self.p1.product_variant_ids[0]
line_form.product_qty = 1
self.p3_bom_id = mrp_bom_form.save()

View File

@@ -1,10 +1,14 @@
from odoo.exceptions import UserError, ValidationError from odoo.exceptions import UserError, ValidationError
from odoo.tests import Form from odoo.tests import Form
from .common import TestMrpBomAttributeMatchBase from .common import TestMrpAttachmentMgmtBase
class TestMrpBomAttributeMatch(TestMrpBomAttributeMatchBase): class TestMrpAttachmentMgmt(TestMrpAttachmentMgmtBase):
@classmethod
def setUpClass(cls):
super().setUpClass()
def test_bom_1(self): def test_bom_1(self):
mrp_bom_form = Form(self.env["mrp.bom"]) mrp_bom_form = Form(self.env["mrp.bom"])
mrp_bom_form.product_tmpl_id = self.product_sword mrp_bom_form.product_tmpl_id = self.product_sword
@@ -53,18 +57,18 @@ class TestMrpBomAttributeMatch(TestMrpBomAttributeMatchBase):
plastic_smells_like_orchid.unlink() plastic_smells_like_orchid.unlink()
def test_manufacturing_order_1(self): def test_manufacturing_order_1(self):
sword_cyan = self.product_sword.product_variant_ids[0]
plastic_cyan = self.product_plastic.product_variant_ids[0]
mo_form = Form(self.env["mrp.production"]) mo_form = Form(self.env["mrp.production"])
mo_form.product_id = sword_cyan mo_form.product_id = self.product_sword.product_variant_ids.filtered(
lambda x: x.display_name == "Plastic Sword (Cyan)"
)
mo_form.bom_id = self.bom_id mo_form.bom_id = self.bom_id
mo_form.product_qty = 1 mo_form.product_qty = 1
self.mo_sword = mo_form.save() self.mo_sword = mo_form.save()
self.mo_sword.action_confirm() self.mo_sword.action_confirm()
# Assert correct component variant was selected automatically # Assert correct component variant was selected automatically
self.assertEqual( self.assertEqual(
self.mo_sword.move_raw_ids.product_id, self.mo_sword.move_raw_ids.product_id.display_name,
plastic_cyan + self.product_9, "Plastic Component (Cyan)",
) )
def test_manufacturing_order_2(self): def test_manufacturing_order_2(self):
@@ -154,22 +158,3 @@ class TestMrpBomAttributeMatch(TestMrpBomAttributeMatchBase):
) )
with self.assertRaises(UserError): with self.assertRaises(UserError):
test_bom_3.explode(self.product_9, 1) test_bom_3.explode(self.product_9, 1)
def test_mrp_report_bom_structure(self):
sword_cyan = self.product_sword.product_variant_ids[0]
BomStructureReport = self.env["report.mrp.report_bom_structure"]
res = BomStructureReport._get_report_data(self.bom_id.id)
self.assertTrue(res["is_variant_applied"])
self.assertEqual(res["lines"]["product"], sword_cyan)
self.assertEqual(
res["lines"]["components"][0]["line_id"],
self.bom_id.bom_line_ids[0].id,
)
self.assertEqual(
res["lines"]["components"][1]["line_id"],
self.bom_id.bom_line_ids[1].id,
)
self.assertEqual(
res["lines"]["components"][0]["parent_id"],
self.bom_id.id,
)