mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[ADD] mrp_bom_attribute_match_semifinished_products: Module added.
This commit is contained in:
137
mrp_bom_attribute_match_semifinished_product/README.rst
Normal file
137
mrp_bom_attribute_match_semifinished_product/README.rst
Normal file
@@ -0,0 +1,137 @@
|
||||
=========================================
|
||||
BOM Attribute Match Semifinished Products
|
||||
=========================================
|
||||
|
||||
..
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! source digest: sha256:d38945eaefcb9943ca73a4adc0b52a30e9181cc9fbc36e38f9eee796f68d3bde
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |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/14.0/mrp_bom_attribute_match_semifinished_product
|
||||
:alt: OCA/manufacture
|
||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||
:target: https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_bom_attribute_match_semifinished_product
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
|
||||
:target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=14.0
|
||||
:alt: Try me on Runboat
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
This module makes use of the features provided by module mrp_bom_attribute_match to create, for a finished product:
|
||||
|
||||
* Semi-finished products with relevant attributes and settings
|
||||
* Structure of BoMs to manufacture them.
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Use Cases / Context
|
||||
===================
|
||||
|
||||
In industries like textile and apparel it’s common to have finished products with many variants for color and size, as well as several semi-finished products for various stages of manufacturing - often subcontracted.
|
||||
|
||||
This module leaves to the user only the following manual steps:
|
||||
|
||||
* creation of finished product
|
||||
* creation of BoM for first semi-finished product
|
||||
|
||||
automating the steps in the middle.
|
||||
|
||||
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
To allow a user to use features of this module, enable technical access right "Create finished product structure".
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
In a product template > inventory tab, enable field “Finished product” (note: it can only be enabled for products with variants).
|
||||
|
||||
From product template form, use server action “Create finished product structure”: a wizard is displayed with the following fields:
|
||||
|
||||
* **Stage name**: this field is used to provide a name to the semi-finished product; the name will be set as *product template name* - *stage name* eg: “Customizable desk (CONFIG) - Wood polishing”
|
||||
|
||||
* **Template product**: he semi-finished product will be created as a copy of the product template set in this field, with all the related settings (eg: routes, supplierinfo, product type…).
|
||||
|
||||
Note: only product templates without attributes and values can be set in this field.
|
||||
|
||||
* **Attribute(s)**: this field is used to set which attributes and values to copy from finished product to semi-finished product of this stage.
|
||||
|
||||
Note: each semi-finished product cannot have more attributes than the semi-finished product in previous stage.
|
||||
|
||||
* **BoM type**: the type of Bom to manufacture the previous product in the semi-finished product chain. If Bom Type = Subcontracting, it’s possible to set subcontractors.
|
||||
|
||||
Note: in first stage, set type of BoM to manufacture finished product; in second stage, set type of BoM to manufacture first stage semi-finished product, and so on.
|
||||
|
||||
|
||||
On creation, a BOM for finished product will be created, with:
|
||||
|
||||
* BoM type (and subcontractors) from first line of wizard
|
||||
|
||||
* semi-finished product from first line of wizard as “Component (product template)” in BoM lines
|
||||
|
||||
* attribute match on semi-finished product attributes.
|
||||
|
||||
If a second line was present in wizard, the same will happen for semi-finished product from first line, and so on.
|
||||
|
||||
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 to smash it by providing a detailed and welcomed
|
||||
`feedback <https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_bom_attribute_match_semifinished_product%0Aversion:%2014.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
|
||||
~~~~~~~
|
||||
|
||||
* Cetmix
|
||||
* Ooops
|
||||
|
||||
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-geomer198| image:: https://github.com/geomer198.png?size=40px
|
||||
:target: https://github.com/geomer198
|
||||
:alt: geomer198
|
||||
.. |maintainer-CetmixGitDrone| image:: https://github.com/CetmixGitDrone.png?size=40px
|
||||
:target: https://github.com/CetmixGitDrone
|
||||
:alt: CetmixGitDrone
|
||||
|
||||
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
|
||||
|
||||
|maintainer-geomer198| |maintainer-CetmixGitDrone|
|
||||
|
||||
This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/14.0/mrp_bom_attribute_match_semifinished_product>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
2
mrp_bom_attribute_match_semifinished_product/__init__.py
Normal file
2
mrp_bom_attribute_match_semifinished_product/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import models
|
||||
from . import wizard
|
||||
18
mrp_bom_attribute_match_semifinished_product/__manifest__.py
Normal file
18
mrp_bom_attribute_match_semifinished_product/__manifest__.py
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "BOM Attribute Match Semifinished Products",
|
||||
"version": "14.0.1.0.0",
|
||||
"category": "Manufacturing",
|
||||
"author": "Cetmix, Ooops, Odoo Community Association (OCA)",
|
||||
"summary": "BOM Attribute Match Semifinished Products",
|
||||
"depends": ["mrp_bom_attribute_match"],
|
||||
"maintainers": ["geomer198", "CetmixGitDrone"],
|
||||
"license": "AGPL-3",
|
||||
"website": "https://github.com/OCA/manufacture",
|
||||
"data": [
|
||||
"security/semifinished_product_security.xml",
|
||||
"security/ir.model.access.csv",
|
||||
"views/product_template_views.xml",
|
||||
"views/semi_finished_product_template_line_views.xml",
|
||||
"wizard/finished_product_structure_wizard.xml",
|
||||
],
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
from . import product_template
|
||||
from . import semi_finished_product_template_line
|
||||
@@ -0,0 +1,47 @@
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
_inherit = "product.template"
|
||||
|
||||
finished_product = fields.Boolean()
|
||||
semi_finished_product_tmpl_ids = fields.One2many(
|
||||
comodel_name="semi.finished.product.template.line",
|
||||
inverse_name="product_tmpl_id",
|
||||
)
|
||||
semi_finished_mrp_bom_ids = fields.Many2many(
|
||||
comodel_name="mrp.bom", string="MRP BoM"
|
||||
)
|
||||
|
||||
@api.constrains("finished_product", "attribute_line_ids")
|
||||
def _check_finished_product(self):
|
||||
for rec in self.filtered("finished_product"):
|
||||
if not rec.attribute_line_ids:
|
||||
raise models.UserError(
|
||||
_(
|
||||
"Finished product is meant to be used only "
|
||||
"on products with attributes in order "
|
||||
"to create a BOM structure for its semi-finished "
|
||||
"products based on attribute value match"
|
||||
)
|
||||
)
|
||||
|
||||
def action_finished_product_structure(self):
|
||||
self.ensure_one()
|
||||
if not self.finished_product:
|
||||
raise models.UserError(
|
||||
_(
|
||||
"You can only create finished product structure "
|
||||
'for products marked as "Finished product".'
|
||||
)
|
||||
)
|
||||
return {
|
||||
"name": _("Create finished product structure"),
|
||||
"type": "ir.actions.act_window",
|
||||
"view_mode": "form",
|
||||
"res_model": "finished.product.structure.wizard",
|
||||
"context": {
|
||||
"default_finished_product_id": self.id,
|
||||
},
|
||||
"target": "new",
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class SemiFinishedProductTemplateLine(models.Model):
|
||||
_name = "semi.finished.product.template.line"
|
||||
|
||||
product_tmpl_id = fields.Many2one(comodel_name="product.template")
|
||||
semi_finished_product_tmpl_id = fields.Many2one(
|
||||
comodel_name="product.template", string="Semi-finished Product"
|
||||
)
|
||||
attribute_ids = fields.Many2many(
|
||||
comodel_name="product.attribute",
|
||||
relation="semi_finished_product_template_line_rel",
|
||||
)
|
||||
bom_type = fields.Selection(
|
||||
selection=[
|
||||
("normal", "Manufacture this product"),
|
||||
("phantom", "Kit"),
|
||||
("subcontract", "Subcontracting"),
|
||||
],
|
||||
default="normal",
|
||||
required=True,
|
||||
)
|
||||
partner_ids = fields.Many2many(comodel_name="res.partner", string="Subcontractors")
|
||||
@@ -0,0 +1 @@
|
||||
To allow a user to use features of this module, enable technical access right "Create finished product structure".
|
||||
@@ -0,0 +1,10 @@
|
||||
In industries like textile and apparel it’s common to have finished products with many variants for color and size, as well as several semi-finished products for various stages of manufacturing - often subcontracted.
|
||||
|
||||
This module leaves to the user only the following manual steps:
|
||||
|
||||
* creation of finished product
|
||||
* creation of BoM for first semi-finished product
|
||||
|
||||
automating the steps in the middle.
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
This module makes use of the features provided by module mrp_bom_attribute_match to create, for a finished product:
|
||||
|
||||
* Semi-finished products with relevant attributes and settings
|
||||
* Structure of BoMs to manufacture them.
|
||||
@@ -0,0 +1,28 @@
|
||||
In a product template > inventory tab, enable field “Finished product” (note: it can only be enabled for products with variants).
|
||||
|
||||
From product template form, use server action “Create finished product structure”: a wizard is displayed with the following fields:
|
||||
|
||||
* **Stage name**: this field is used to provide a name to the semi-finished product; the name will be set as *product template name* - *stage name* eg: “Customizable desk (CONFIG) - Wood polishing”
|
||||
|
||||
* **Template product**: he semi-finished product will be created as a copy of the product template set in this field, with all the related settings (eg: routes, supplierinfo, product type…).
|
||||
|
||||
Note: only product templates without attributes and values can be set in this field.
|
||||
|
||||
* **Attribute(s)**: this field is used to set which attributes and values to copy from finished product to semi-finished product of this stage.
|
||||
|
||||
Note: each semi-finished product cannot have more attributes than the semi-finished product in previous stage.
|
||||
|
||||
* **BoM type**: the type of Bom to manufacture the previous product in the semi-finished product chain. If Bom Type = Subcontracting, it’s possible to set subcontractors.
|
||||
|
||||
Note: in first stage, set type of BoM to manufacture finished product; in second stage, set type of BoM to manufacture first stage semi-finished product, and so on.
|
||||
|
||||
|
||||
On creation, a BOM for finished product will be created, with:
|
||||
|
||||
* BoM type (and subcontractors) from first line of wizard
|
||||
|
||||
* semi-finished product from first line of wizard as “Component (product template)” in BoM lines
|
||||
|
||||
* attribute match on semi-finished product attributes.
|
||||
|
||||
If a second line was present in wizard, the same will happen for semi-finished product from first line, and so on.
|
||||
@@ -0,0 +1,4 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_finished_product_structure_wizard,mrp.finished.product.structure.wizard,model_finished_product_structure_wizard,mrp.group_mrp_user,1,1,1,1
|
||||
access_finished_product_structure_line,mrp.finished.product.structure.line,model_finished_product_structure_line,mrp.group_mrp_user,1,1,1,1
|
||||
access_semi_finished_product_template_line,mrp.semi.finished.product.template.line,model_semi_finished_product_template_line,mrp.group_mrp_user,1,1,1,1
|
||||
|
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo noupdate="1">
|
||||
|
||||
<record id="group_create_finished_product_structure" model="res.groups">
|
||||
<field name="name">Create finished product structure</field>
|
||||
<field name="implied_ids" eval="[(4, ref('base.group_user'))]" />
|
||||
<field name="category_id" ref="base.module_category_hidden" />
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -0,0 +1,463 @@
|
||||
<?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: https://docutils.sourceforge.io/" />
|
||||
<title>BOM Attribute Match Semifinished Products</title>
|
||||
<style type="text/css">
|
||||
|
||||
/*
|
||||
:Author: David Goodger (goodger@python.org)
|
||||
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
|
||||
:Copyright: This stylesheet has been placed in the public domain.
|
||||
|
||||
Default cascading style sheet for the HTML output of Docutils.
|
||||
|
||||
See https://docutils.sourceforge.io/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="bom-attribute-match-semifinished-products">
|
||||
<h1 class="title">BOM Attribute Match Semifinished Products</h1>
|
||||
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! source digest: sha256:d38945eaefcb9943ca73a4adc0b52a30e9181cc9fbc36e38f9eee796f68d3bde
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/manufacture/tree/14.0/mrp_bom_attribute_match_semifinished_product"><img alt="OCA/manufacture" src="https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_bom_attribute_match_semifinished_product"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
|
||||
<p>This module makes use of the features provided by module mrp_bom_attribute_match to create, for a finished product:</p>
|
||||
<ul class="simple">
|
||||
<li>Semi-finished products with relevant attributes and settings</li>
|
||||
<li>Structure of BoMs to manufacture them.</li>
|
||||
</ul>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="#use-cases-context" id="toc-entry-1">Use Cases / Context</a></li>
|
||||
<li><a class="reference internal" href="#configuration" id="toc-entry-2">Configuration</a></li>
|
||||
<li><a class="reference internal" href="#usage" id="toc-entry-3">Usage</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-4">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="toc-entry-5">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="toc-entry-6">Authors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="use-cases-context">
|
||||
<h1><a class="toc-backref" href="#toc-entry-1">Use Cases / Context</a></h1>
|
||||
<p>In industries like textile and apparel it’s common to have finished products with many variants for color and size, as well as several semi-finished products for various stages of manufacturing - often subcontracted.</p>
|
||||
<p>This module leaves to the user only the following manual steps:</p>
|
||||
<ul class="simple">
|
||||
<li>creation of finished product</li>
|
||||
<li>creation of BoM for first semi-finished product</li>
|
||||
</ul>
|
||||
<p>automating the steps in the middle.</p>
|
||||
</div>
|
||||
<div class="section" id="configuration">
|
||||
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
|
||||
<p>To allow a user to use features of this module, enable technical access right “Create finished product structure”.</p>
|
||||
</div>
|
||||
<div class="section" id="usage">
|
||||
<h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
|
||||
<p>In a product template > inventory tab, enable field “Finished product” (note: it can only be enabled for products with variants).</p>
|
||||
<p>From product template form, use server action “Create finished product structure”: a wizard is displayed with the following fields:</p>
|
||||
<ul>
|
||||
<li><p class="first"><strong>Stage name</strong>: this field is used to provide a name to the semi-finished product; the name will be set as <em>product template name</em> - <em>stage name</em> eg: “Customizable desk (CONFIG) - Wood polishing”</p>
|
||||
</li>
|
||||
<li><p class="first"><strong>Template product</strong>: he semi-finished product will be created as a copy of the product template set in this field, with all the related settings (eg: routes, supplierinfo, product type…).</p>
|
||||
<p>Note: only product templates without attributes and values can be set in this field.</p>
|
||||
</li>
|
||||
<li><p class="first"><strong>Attribute(s)</strong>: this field is used to set which attributes and values to copy from finished product to semi-finished product of this stage.</p>
|
||||
<p>Note: each semi-finished product cannot have more attributes than the semi-finished product in previous stage.</p>
|
||||
</li>
|
||||
<li><p class="first"><strong>BoM type</strong>: the type of Bom to manufacture the previous product in the semi-finished product chain. If Bom Type = Subcontracting, it’s possible to set subcontractors.</p>
|
||||
<p>Note: in first stage, set type of BoM to manufacture finished product; in second stage, set type of BoM to manufacture first stage semi-finished product, and so on.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<p>On creation, a BOM for finished product will be created, with:</p>
|
||||
<ul class="simple">
|
||||
<li>BoM type (and subcontractors) from first line of wizard</li>
|
||||
<li>semi-finished product from first line of wizard as “Component (product template)” in BoM lines</li>
|
||||
<li>attribute match on semi-finished product attributes.</li>
|
||||
</ul>
|
||||
<p>If a second line was present in wizard, the same will happen for semi-finished product from first line, and so on.</p>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h1><a class="toc-backref" href="#toc-entry-4">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 to smash it by providing a detailed and welcomed
|
||||
<a class="reference external" href="https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_bom_attribute_match_semifinished_product%0Aversion:%2014.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="#toc-entry-5">Credits</a></h1>
|
||||
<div class="section" id="authors">
|
||||
<h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Cetmix</li>
|
||||
<li>Ooops</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h2><a class="toc-backref" href="#toc-entry-7">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">maintainers</a>:</p>
|
||||
<p><a class="reference external image-reference" href="https://github.com/geomer198"><img alt="geomer198" src="https://github.com/geomer198.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/CetmixGitDrone"><img alt="CetmixGitDrone" src="https://github.com/CetmixGitDrone.png?size=40px" /></a></p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/manufacture/tree/14.0/mrp_bom_attribute_match_semifinished_product">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>
|
||||
@@ -0,0 +1,3 @@
|
||||
from . import test_finished_product_common
|
||||
from . import test_finished_product_structure
|
||||
from . import test_product_template
|
||||
@@ -0,0 +1,32 @@
|
||||
from odoo.tests import Form, TransactionCase
|
||||
|
||||
|
||||
class TestFinishedProductCommon(TransactionCase):
|
||||
def setUp(self):
|
||||
super(TestFinishedProductCommon, self).setUp()
|
||||
|
||||
# Legs Attribute
|
||||
self.legs_attribute = self.env.ref("product.product_attribute_1")
|
||||
self.legs_steel_attr_value = self.env.ref("product.product_attribute_value_1")
|
||||
self.legs_aluminium_attr_value = self.env.ref(
|
||||
"product.product_attribute_value_2"
|
||||
)
|
||||
|
||||
# Color Attribute
|
||||
self.color_attribute = self.env.ref("product.product_attribute_2")
|
||||
self.color_white_attr_value = self.env.ref("product.product_attribute_value_3")
|
||||
self.color_black_attr_value = self.env.ref("product.product_attribute_value_4")
|
||||
|
||||
# Create Valid Product
|
||||
form = Form(self.env["product.template"])
|
||||
form.name = "Product #1"
|
||||
form.finished_product = True
|
||||
with form.attribute_line_ids.new() as attribute:
|
||||
attribute.attribute_id = self.legs_attribute
|
||||
attribute.value_ids.add(self.legs_steel_attr_value)
|
||||
attribute.value_ids.add(self.legs_aluminium_attr_value)
|
||||
with form.attribute_line_ids.new() as attribute:
|
||||
attribute.attribute_id = self.color_attribute
|
||||
attribute.value_ids.add(self.color_white_attr_value)
|
||||
attribute.value_ids.add(self.color_black_attr_value)
|
||||
self.product_1 = form.save()
|
||||
@@ -0,0 +1,249 @@
|
||||
from odoo.exceptions import MissingError, UserError
|
||||
from odoo.tests import Form
|
||||
|
||||
from .test_finished_product_common import TestFinishedProductCommon
|
||||
|
||||
|
||||
class TestFinishedProductStructure(TestFinishedProductCommon):
|
||||
def setUp(self):
|
||||
super(TestFinishedProductStructure, self).setUp()
|
||||
self.size_attr = self.env["product.attribute"].create({"name": "Size"})
|
||||
self.size_attr_value_s = self.env["product.attribute.value"].create(
|
||||
{"name": "S", "attribute_id": self.size_attr.id}
|
||||
)
|
||||
self.size_attr_value_m = self.env["product.attribute.value"].create(
|
||||
{"name": "M", "attribute_id": self.size_attr.id}
|
||||
)
|
||||
self.size_attr_value_l = self.env["product.attribute.value"].create(
|
||||
{"name": "L", "attribute_id": self.size_attr.id}
|
||||
)
|
||||
form = Form(self.env["product.template"])
|
||||
form.name = "Product #1"
|
||||
form.finished_product = True
|
||||
with form.attribute_line_ids.new() as attribute:
|
||||
attribute.attribute_id = self.color_attribute
|
||||
attribute.value_ids.add(self.color_white_attr_value)
|
||||
attribute.value_ids.add(self.color_black_attr_value)
|
||||
self.product_2 = form.save()
|
||||
|
||||
form = Form(self.env["product.template"])
|
||||
form.name = "Product #1"
|
||||
form.finished_product = True
|
||||
with form.attribute_line_ids.new() as attribute:
|
||||
attribute.attribute_id = self.legs_attribute
|
||||
attribute.value_ids.add(self.legs_steel_attr_value)
|
||||
attribute.value_ids.add(self.legs_aluminium_attr_value)
|
||||
self.product_3 = form.save()
|
||||
|
||||
self.stage_1_product = self.env["product.template"].create(
|
||||
{"name": "Product #1 Stage #1"}
|
||||
)
|
||||
self.stage_2_product = self.env["product.template"].create(
|
||||
{"name": "Product #2 Stage #2"}
|
||||
)
|
||||
|
||||
self.partner_subcontractor = self.env["res.partner"].create(
|
||||
{"name": "Subcontractor #1"}
|
||||
)
|
||||
self.product_shirt_template = self.env["product.template"].create(
|
||||
{
|
||||
"name": "Shirt",
|
||||
"attribute_line_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"attribute_id": self.size_attr.id,
|
||||
"value_ids": [(6, 0, [self.size_attr_value_l.id])],
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
def test_structure_without_lines(self):
|
||||
form = Form(
|
||||
self.env["finished.product.structure.wizard"].with_context(
|
||||
default_finished_product_id=self.product_1.id
|
||||
)
|
||||
)
|
||||
wizard = form.save()
|
||||
with self.assertRaises(MissingError):
|
||||
wizard.create_product_struct()
|
||||
|
||||
def test_structure_check_attributes(self):
|
||||
with Form(
|
||||
self.env["finished.product.structure.wizard"].with_context(
|
||||
default_finished_product_id=self.product_1.id
|
||||
)
|
||||
) as form:
|
||||
attribute_ids = form._values.get("attribute_ids")[0][2]
|
||||
self.assertListEqual(
|
||||
attribute_ids,
|
||||
[self.legs_attribute.id, self.color_attribute.id],
|
||||
msg="List attributes IDS must be the same",
|
||||
)
|
||||
form.finished_product_id = self.product_2
|
||||
attribute_ids = form._values.get("attribute_ids")[0][2]
|
||||
self.assertListEqual(
|
||||
attribute_ids,
|
||||
self.color_attribute.ids,
|
||||
msg="List attributes IDS must be the same",
|
||||
)
|
||||
form.finished_product_id = self.product_3
|
||||
attribute_ids = form._values.get("attribute_ids")[0][2]
|
||||
self.assertListEqual(
|
||||
attribute_ids,
|
||||
self.legs_attribute.ids,
|
||||
msg="List attributes IDS must be the same",
|
||||
)
|
||||
with self.assertRaises(UserError), form.line_ids.new() as line:
|
||||
line.stage_name = "Stage 1"
|
||||
line.product_tmpl_id = self.product_shirt_template
|
||||
line.bom_type = "normal"
|
||||
|
||||
def test_tmp_product_struct_line(self):
|
||||
wizard = self.env["finished.product.structure.wizard"].create(
|
||||
{"finished_product_id": self.product_1.id}
|
||||
)
|
||||
tmp_record = wizard._tmp_product_struct_line()
|
||||
self.assertRecordValues(
|
||||
tmp_record,
|
||||
[
|
||||
{
|
||||
"stage_name": "{} - Start".format(self.product_1.name),
|
||||
"product_tmpl_id": self.product_1.id,
|
||||
"product_tmpl_stage_id": self.product_1.id,
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
def _create_product_struct(self, product_id):
|
||||
form = Form(
|
||||
self.env["finished.product.structure.wizard"].with_context(
|
||||
default_finished_product_id=product_id
|
||||
)
|
||||
)
|
||||
with form.line_ids.new() as line:
|
||||
line.stage_name = "Stage #1"
|
||||
line.product_tmpl_id = self.stage_1_product
|
||||
line.bom_type = "normal"
|
||||
with form.line_ids.new() as line:
|
||||
line.stage_name = "Stage #2"
|
||||
line.product_tmpl_id = self.stage_2_product
|
||||
line.bom_type = "normal"
|
||||
return form.save()
|
||||
|
||||
def test_create_product_struct(self):
|
||||
wizard = self._create_product_struct(self.product_1.id)
|
||||
result = wizard.create_product_struct()
|
||||
self.assertDictEqual(
|
||||
result,
|
||||
{"type": "ir.actions.act_window_close"},
|
||||
msg="Dicts must be the same",
|
||||
)
|
||||
self.assertEqual(
|
||||
len(self.product_1.semi_finished_product_tmpl_ids),
|
||||
2,
|
||||
msg="Products count must be equal to 2",
|
||||
)
|
||||
product_line_1, product_line_2 = self.product_1.semi_finished_product_tmpl_ids
|
||||
self.assertEqual(
|
||||
len(self.product_1.semi_finished_mrp_bom_ids),
|
||||
2,
|
||||
msg="BOM's count must be equal to 2",
|
||||
)
|
||||
bom_1, bom_2 = self.product_1.semi_finished_mrp_bom_ids
|
||||
# Bom 1
|
||||
self.assertEqual(
|
||||
bom_1.product_tmpl_id,
|
||||
self.product_1,
|
||||
msg="Bom product must be equal to ID #{}".format(self.product_1.id),
|
||||
)
|
||||
line_ids = bom_1.bom_line_ids
|
||||
self.assertEqual(
|
||||
line_ids.component_template_id,
|
||||
product_line_1.semi_finished_product_tmpl_id,
|
||||
msg="Bom component product must be equal to ID #{}".format(
|
||||
product_line_1.semi_finished_product_tmpl_id.id
|
||||
),
|
||||
)
|
||||
self.assertListEqual(
|
||||
line_ids.match_on_attribute_ids.ids,
|
||||
[self.legs_attribute.id, self.color_attribute.id],
|
||||
msg="Attributes must be the same",
|
||||
)
|
||||
# Bom 2
|
||||
self.assertEqual(
|
||||
bom_2.product_tmpl_id,
|
||||
product_line_1.semi_finished_product_tmpl_id,
|
||||
msg="Bom product must be equal to ID #{}".format(
|
||||
product_line_1.semi_finished_product_tmpl_id.id
|
||||
),
|
||||
)
|
||||
line_ids = bom_2.bom_line_ids
|
||||
self.assertEqual(
|
||||
line_ids.component_template_id,
|
||||
product_line_2.semi_finished_product_tmpl_id,
|
||||
msg="Bom component product must be equal to ID #{}".format(
|
||||
product_line_2.semi_finished_product_tmpl_id.id
|
||||
),
|
||||
)
|
||||
self.assertListEqual(
|
||||
line_ids.match_on_attribute_ids.ids,
|
||||
[self.legs_attribute.id, self.color_attribute.id],
|
||||
msg="Attributes must be the same",
|
||||
)
|
||||
|
||||
def test_recreate_product_struct(self):
|
||||
wizard = self._create_product_struct(self.product_1.id)
|
||||
wizard.create_product_struct()
|
||||
semi_first_product_ids = self.product_1.semi_finished_product_tmpl_ids.ids
|
||||
bom_first_ids = self.product_1.semi_finished_product_tmpl_ids.ids
|
||||
# Recreate structure
|
||||
wizard = self._create_product_struct(self.product_1.id)
|
||||
wizard.create_product_struct()
|
||||
semi_second_product_ids = self.product_1.semi_finished_product_tmpl_ids.ids
|
||||
bom_second_ids = self.product_1.semi_finished_product_tmpl_ids.ids
|
||||
self.assertNotEqual(semi_first_product_ids, semi_second_product_ids)
|
||||
self.assertNotEqual(bom_first_ids, bom_second_ids)
|
||||
|
||||
def test_prepare_bom_by_products(self):
|
||||
form = Form(
|
||||
self.env["finished.product.structure.wizard"].with_context(
|
||||
default_finished_product_id=self.product_1
|
||||
)
|
||||
)
|
||||
with form.line_ids.new() as line:
|
||||
line.stage_name = "Stage #1"
|
||||
line.product_tmpl_id = self.stage_1_product
|
||||
line.bom_type = "normal"
|
||||
with form.line_ids.new() as line:
|
||||
line.stage_name = "Stage #2"
|
||||
line.product_tmpl_id = self.stage_2_product
|
||||
line.bom_type = "subcontract"
|
||||
line.partner_ids.add(self.partner_subcontractor)
|
||||
wizard = form.save()
|
||||
vals = wizard._prepare_bom_by_products()
|
||||
bom_1_vals, bom_2_vals = vals
|
||||
self.assertEqual(
|
||||
bom_1_vals.get("product_tmpl_id"),
|
||||
self.product_1.id,
|
||||
msg="Product Template must be equal to ID #{}".format(self.product_1.id),
|
||||
)
|
||||
self.assertEqual(
|
||||
bom_1_vals.get("type"), "normal", msg="Bom type must be equal to normal"
|
||||
)
|
||||
self.assertFalse(
|
||||
bom_2_vals.get("product_tmpl_id"), msg="Product Template not set"
|
||||
)
|
||||
self.assertEqual(
|
||||
bom_2_vals.get("type"),
|
||||
"subcontract",
|
||||
msg="Bom type must be equal to 'subcontract'",
|
||||
)
|
||||
self.assertEqual(
|
||||
bom_2_vals.get("subcontractor_ids")[0][2],
|
||||
self.partner_subcontractor.ids,
|
||||
msg="Partner subcontractor must be contains in bom vals",
|
||||
)
|
||||
@@ -0,0 +1,52 @@
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tests import Form
|
||||
|
||||
from .test_finished_product_common import TestFinishedProductCommon
|
||||
|
||||
|
||||
class TestProductTemplate(TestFinishedProductCommon):
|
||||
def test_create_product_template_without_attributes(self):
|
||||
"""Test flow when finished product created without attributes"""
|
||||
form = Form(self.env["product.template"])
|
||||
form.name = "Product #2"
|
||||
form.finished_product = True
|
||||
with self.assertRaises(UserError):
|
||||
form.save()
|
||||
|
||||
def test_edit_attributes_in_finished_product_template(self):
|
||||
"""Test flow when all attribute is removed from finished product"""
|
||||
with self.assertRaises(UserError), Form(self.product_1) as form:
|
||||
form.attribute_line_ids.remove(index=1)
|
||||
form.attribute_line_ids.remove(index=0)
|
||||
|
||||
def test_action_finished_product_structure_invalid(self):
|
||||
"""Test flow when action is raised error for not finished product"""
|
||||
self.product_1.finished_product = False
|
||||
with self.assertRaises(UserError):
|
||||
self.product_1.action_finished_product_structure()
|
||||
|
||||
def test_action_finished_product_structure_valid(self):
|
||||
"""Test flow when action is correct for finished product"""
|
||||
action = self.product_1.action_finished_product_structure()
|
||||
self.assertEqual(
|
||||
action.get("type"),
|
||||
"ir.actions.act_window",
|
||||
msg="Action type must be equal to 'ir.actions.act_window'",
|
||||
)
|
||||
self.assertEqual(
|
||||
action.get("view_mode"),
|
||||
"form",
|
||||
msg="Action view mode must be equal to 'form'",
|
||||
)
|
||||
self.assertEqual(
|
||||
action.get("res_model"),
|
||||
"finished.product.structure.wizard",
|
||||
msg="Action res model must be equal to 'finished.product.structure.wizard'",
|
||||
)
|
||||
self.assertEqual(
|
||||
action.get("target"), "new", msg="Action target must be equal to 'new'"
|
||||
)
|
||||
context = {"default_finished_product_id": self.product_1.id}
|
||||
self.assertDictEqual(
|
||||
action.get("context"), context, msg="Contexts must be the same"
|
||||
)
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="product_template_form_view_inherit" model="ir.ui.view">
|
||||
<field name="name">product.template_procurement.inherit.form.view</field>
|
||||
<field name="model">product.template</field>
|
||||
<field
|
||||
name="inherit_id"
|
||||
ref="stock.product_template_form_view_procurement_button"
|
||||
/>
|
||||
<field name="arch" type="xml">
|
||||
<group name="operations" position="inside">
|
||||
<field
|
||||
name="finished_product"
|
||||
attrs="{'invisible': [('attribute_line_ids', '=', [])]}"
|
||||
/>
|
||||
</group>
|
||||
<notebook position="inside">
|
||||
<page
|
||||
name="manufacture_page"
|
||||
string="Finished Product Structure"
|
||||
groups="base.group_no_one"
|
||||
attrs="{'invisible': [('finished_product', '=', False)]}"
|
||||
>
|
||||
<group>
|
||||
<field
|
||||
name="semi_finished_mrp_bom_ids"
|
||||
widget="many2many_tags"
|
||||
readonly="1"
|
||||
/>
|
||||
</group>
|
||||
<field
|
||||
name="semi_finished_product_tmpl_ids"
|
||||
widget="one2many"
|
||||
readonly="1"
|
||||
>
|
||||
<tree>
|
||||
<field name="product_tmpl_id" invisible="1" />
|
||||
<field name="semi_finished_product_tmpl_id" />
|
||||
<field name="attribute_ids" widget="many2many_tags" />
|
||||
<field name="bom_type" />
|
||||
<field name="partner_ids" widget="many2many_tags" />
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="semi_finished_product_template_line_view_form" model="ir.ui.view">
|
||||
<field name="name">semi.finished.product.template.line.view.form</field>
|
||||
<field name="model">semi.finished.product.template.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="product_tmpl_id" readonly="1" />
|
||||
<field name="semi_finished_product_tmpl_id" />
|
||||
<field name="attribute_ids" widget="many2many_tags" />
|
||||
<field name="bom_type" />
|
||||
<field
|
||||
name="partner_ids"
|
||||
attrs="{'invisible': [('bom_type', '!=', 'subcontract')]}"
|
||||
/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -0,0 +1,2 @@
|
||||
from . import finished_product_structure_line
|
||||
from . import finished_product_structure_wizard
|
||||
@@ -0,0 +1,56 @@
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
|
||||
class FinishedProductStructureLine(models.TransientModel):
|
||||
_name = "finished.product.structure.line"
|
||||
|
||||
structure_id = fields.Many2one("finished.product.structure.wizard")
|
||||
stage_name = fields.Char(required=True)
|
||||
product_tmpl_id = fields.Many2one(
|
||||
comodel_name="product.template",
|
||||
required=True,
|
||||
string="Template product",
|
||||
)
|
||||
valid_attribute_ids = fields.Many2many(
|
||||
comodel_name="product.attribute",
|
||||
relation="product_attribute_valid_rel",
|
||||
)
|
||||
attribute_ids = fields.Many2many(
|
||||
comodel_name="product.attribute",
|
||||
relation="finished_product_struct_line_attribute_rel",
|
||||
domain="[('id', 'in', valid_attribute_ids)]",
|
||||
required=True,
|
||||
string="Attribute(s)",
|
||||
)
|
||||
bom_type = fields.Selection(
|
||||
selection=[
|
||||
("normal", "Manufacture this product"),
|
||||
("phantom", "Kit"),
|
||||
("subcontract", "Subcontracting"),
|
||||
],
|
||||
default="normal",
|
||||
required=True,
|
||||
)
|
||||
partner_ids = fields.Many2many(comodel_name="res.partner", string="Subcontractor")
|
||||
product_tmpl_stage_id = fields.Many2one(comodel_name="product.template")
|
||||
|
||||
@api.onchange("product_tmpl_id")
|
||||
def _onchange_product_tmpl_id(self):
|
||||
self._check_product_tmpl_id()
|
||||
|
||||
@api.constrains("product_tmpl_id")
|
||||
def _check_product_tmpl_id(self):
|
||||
for rec in self:
|
||||
if rec.product_tmpl_id.attribute_line_ids:
|
||||
raise models.ValidationError(
|
||||
_(
|
||||
"You can only add products without attributes as 'Template products'."
|
||||
)
|
||||
)
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
result = super(FinishedProductStructureLine, self).default_get(fields)
|
||||
if result.get("valid_attribute_ids"):
|
||||
result["attribute_ids"] = result["valid_attribute_ids"]
|
||||
return result
|
||||
@@ -0,0 +1,139 @@
|
||||
from itertools import tee
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
|
||||
def pairwise(iterable):
|
||||
"""s -> (s0,s1), (s1,s2), (s2, s3), ..."""
|
||||
a, b = tee(iterable)
|
||||
next(b, None)
|
||||
return zip(a, b)
|
||||
|
||||
|
||||
class FinishedProductStructureWizard(models.TransientModel):
|
||||
_name = "finished.product.structure.wizard"
|
||||
|
||||
finished_product_id = fields.Many2one(
|
||||
comodel_name="product.template",
|
||||
domain="[('finished_product', '=', True)]",
|
||||
required=True,
|
||||
)
|
||||
line_ids = fields.One2many(
|
||||
comodel_name="finished.product.structure.line", inverse_name="structure_id"
|
||||
)
|
||||
attribute_ids = fields.Many2many(
|
||||
comodel_name="product.attribute", compute="_compute_attribute_ids", store=True
|
||||
)
|
||||
need_confirmation = fields.Boolean()
|
||||
|
||||
@api.onchange("finished_product_id")
|
||||
def _onchange_finished_product_id(self):
|
||||
"""
|
||||
Update attribute and line attributes
|
||||
by onchange finished product
|
||||
"""
|
||||
self.line_ids.write({"attribute_ids": [(6, 0, self.attribute_ids.ids)]})
|
||||
self.need_confirmation = bool(
|
||||
self.finished_product_id.semi_finished_mrp_bom_ids
|
||||
)
|
||||
|
||||
@api.depends("finished_product_id")
|
||||
def _compute_attribute_ids(self):
|
||||
for rec in self:
|
||||
rec.attribute_ids = rec.finished_product_id.attribute_line_ids.mapped(
|
||||
"attribute_id"
|
||||
)
|
||||
|
||||
def _prepare_new_product_templates(self):
|
||||
finished_product = self.finished_product_id
|
||||
for line in self.line_ids:
|
||||
new_product_name = "{} - {}".format(finished_product.name, line.stage_name)
|
||||
product_tmpl = line.product_tmpl_id.copy({"name": new_product_name})
|
||||
attr_lines = finished_product.attribute_line_ids.filtered(
|
||||
lambda pl: pl.attribute_id in line.attribute_ids
|
||||
)
|
||||
for attr_line in attr_lines:
|
||||
attr_line.copy({"product_tmpl_id": product_tmpl.id})
|
||||
line.product_tmpl_stage_id = product_tmpl
|
||||
|
||||
def _tmp_product_struct_line(self):
|
||||
self.ensure_one()
|
||||
return self.env["finished.product.structure.line"].new(
|
||||
{
|
||||
"stage_name": "{} - Start".format(self.finished_product_id.name),
|
||||
"product_tmpl_id": self.finished_product_id,
|
||||
"product_tmpl_stage_id": self.finished_product_id,
|
||||
}
|
||||
)
|
||||
|
||||
def _prepare_bom_by_products(self):
|
||||
lines = self._tmp_product_struct_line() | self.line_ids
|
||||
vals_list = []
|
||||
for bom, line in pairwise(lines):
|
||||
vals = {
|
||||
"product_tmpl_id": bom.product_tmpl_stage_id.id,
|
||||
"type": line.bom_type,
|
||||
"bom_line_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"component_template_id": line.product_tmpl_stage_id.id,
|
||||
"match_on_attribute_ids": [(6, 0, line.attribute_ids.ids)],
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
if line.bom_type == "subcontract":
|
||||
vals.update(subcontractor_ids=[(6, 0, line.partner_ids.ids)])
|
||||
self.finished_product_id.write(
|
||||
{
|
||||
"semi_finished_product_tmpl_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"semi_finished_product_tmpl_id": line.product_tmpl_stage_id.id,
|
||||
"attribute_ids": [(6, 0, line.attribute_ids.ids)],
|
||||
"bom_type": line.bom_type,
|
||||
"partner_ids": [(6, 0, line.partner_ids.ids)],
|
||||
},
|
||||
)
|
||||
]
|
||||
}
|
||||
)
|
||||
vals_list.append(vals)
|
||||
return vals_list
|
||||
|
||||
def remove_old_struct(self):
|
||||
boms = self.finished_product_id.semi_finished_mrp_bom_ids
|
||||
if boms:
|
||||
archive_bom_ids = (
|
||||
self.env["mrp.production"]
|
||||
.search(
|
||||
[
|
||||
("bom_id", "in", boms.ids),
|
||||
("state", "not in", ["done", "cancel"]),
|
||||
]
|
||||
)
|
||||
.mapped("bom_id")
|
||||
)
|
||||
(boms - archive_bom_ids).unlink()
|
||||
archive_bom_ids.write({"active": False})
|
||||
lines = self.finished_product_id.semi_finished_product_tmpl_ids
|
||||
if lines:
|
||||
products = lines.mapped("semi_finished_product_tmpl_id")
|
||||
lines.unlink()
|
||||
products.unlink()
|
||||
|
||||
def create_product_struct(self):
|
||||
if not self.line_ids:
|
||||
raise models.MissingError(
|
||||
_("At least one line needs to be added to structure.")
|
||||
)
|
||||
self.remove_old_struct()
|
||||
self._prepare_new_product_templates()
|
||||
vals_list = self._prepare_bom_by_products()
|
||||
bom_ids = self.env["mrp.bom"].create(vals_list)
|
||||
self.finished_product_id.semi_finished_mrp_bom_ids = bom_ids
|
||||
return {"type": "ir.actions.act_window_close"}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="finished_product_structure_wizard" model="ir.ui.view">
|
||||
<field name="name">finished.product.structure.wizard.form.view</field>
|
||||
<field name="model">finished.product.structure.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Finished Product Structure">
|
||||
<group>
|
||||
<field name="finished_product_id" />
|
||||
<field name="attribute_ids" widget="many2many_tags" readonly="1" />
|
||||
</group>
|
||||
<field
|
||||
name="line_ids"
|
||||
nolabel="1"
|
||||
attrs="{'invisible': [('finished_product_id', '=', False)]}"
|
||||
context="{'default_valid_attribute_ids': attribute_ids}"
|
||||
widget="one2many"
|
||||
>
|
||||
<tree editable="bottom">
|
||||
<field name="structure_id" invisible="1" />
|
||||
<field name="valid_attribute_ids" invisible="1" />
|
||||
<field name="stage_name" />
|
||||
<field name="product_tmpl_id" />
|
||||
<field name="attribute_ids" widget="many2many_tags" />
|
||||
<field name="bom_type" />
|
||||
<field
|
||||
name="partner_ids"
|
||||
widget="many2many_tags"
|
||||
attrs="{'readonly': [('bom_type', '!=', 'subcontract')]}"
|
||||
/>
|
||||
</tree>
|
||||
</field>
|
||||
<footer>
|
||||
<field name="need_confirmation" invisible="1" />
|
||||
<button
|
||||
string="Create"
|
||||
name="create_product_struct"
|
||||
type="object"
|
||||
class="btn-primary"
|
||||
attrs="{'invisible': [('need_confirmation', '=', True)]}"
|
||||
/>
|
||||
<button
|
||||
string="Create"
|
||||
name="create_product_struct"
|
||||
type="object"
|
||||
class="btn-primary"
|
||||
attrs="{'invisible': [('need_confirmation', '=', False)]}"
|
||||
confirm="Semifinished product(s) and BoM(s) have already been created for this finished product. By clicking Create, existing semifinished products and Boms will be deleted or archived, and replaced by new ones."
|
||||
/>
|
||||
<button string="Cancel" class="btn-default" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_finished_product_structure" model="ir.actions.server">
|
||||
<field name="name">Create finished product structure</field>
|
||||
<field name="model_id" ref="product.model_product_template" />
|
||||
<field
|
||||
name="groups_id"
|
||||
eval="[(4, ref('mrp_bom_attribute_match_semifinished_product.group_create_finished_product_structure'))]"
|
||||
/>
|
||||
<field name="binding_model_id" ref="product.model_product_template" />
|
||||
<field name="binding_view_types">form</field>
|
||||
<field name="state">code</field>
|
||||
<field name="code">
|
||||
if records:
|
||||
action = records.action_finished_product_structure()
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user