[ADD] mrp_bom_attribute_match_duplicate_kit: Module added.

This commit is contained in:
geomer198
2023-12-07 01:41:00 +04:00
parent 384ef2468b
commit b49ca1d8fe
22 changed files with 916 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
=================================
BOM Attribute Match Duplicate Kit
=================================
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:799dde4fcb103960a4af12b6bd212c0913ffd0f478293ff3c0fd559245ecae1a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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_duplicate_kit
: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_duplicate_kit
: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 allows to duplicate a product with variants, at the same time creating a BoM with type "Kit" for the new product mapping variants of the original product.
This is useful when managing products that only exist as a "front" for a product with another name, to avoid having to manually map variants in BOM.
**Table of contents**
.. contents::
:local:
Use Cases / Context
===================
The use case is that customer sells the same product with two different names, prices, etc - but on the stock side, **Product 1 (copy)** only exists as a kit of **Product 1** (they're physically the same product)
Usage
=====
* Open "Product 1" with variants
* Use server action: "Duplicate with attribute match kit"
* A wizard opens up with field "New product template name"
* Inputs name for duplicated product (eg: "Fancy Product 1")
* Click Confirm
A new product is created with name "Fancy Product 1" and a new BOM of type "kit" for this product;
If product does not have variants, when using server action, display error message: "This server action can be used only on products with variants".
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_duplicate_kit%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
Contributors
~~~~~~~~~~~~
* Ooops404 <https://www.ooops404.com/>
* Francesco Foresti <francesco.foresti@ooops404.com>
* Cetmix <https://cetmix.com/>
* Maksim Shurupov
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-aleuffre| image:: https://github.com/aleuffre.png?size=40px
:target: https://github.com/aleuffre
:alt: aleuffre
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-aleuffre|
This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/14.0/mrp_bom_attribute_match_duplicate_kit>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

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

View File

@@ -0,0 +1,19 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "BOM Attribute Match Duplicate Kit",
"version": "14.0.1.0.0",
"category": "Manufacturing",
"author": "Cetmix, Ooops, Odoo Community Association (OCA)",
"summary": "BOM Attribute Match Duplicate Kit",
"maintainers": ["aleuffre"],
"depends": ["mrp_bom_attribute_match"],
"license": "AGPL-3",
"website": "https://github.com/OCA/manufacture",
"data": [
"security/ir.model.access.csv",
"views/product_template_views.xml",
"wizard/product_template_kit_wizard.xml",
],
}

View File

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

View File

@@ -0,0 +1,26 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, models
class ProductTemplate(models.Model):
_inherit = "product.template"
def action_duplicate_with_kit(self):
self.ensure_one()
if self.product_variant_count == 1:
raise models.UserError(
_("This server action can be used only on products with variants")
)
return {
"name": _("Duplicate with attribute match kit"),
"type": "ir.actions.act_window",
"view_mode": "form",
"res_model": "product.template.kit.wizard",
"context": {
"default_product_tmpl_id": self.id,
"default_new_product_template_name": "{} 1".format(self.name),
},
"target": "new",
}

View File

@@ -0,0 +1 @@
The use case is that customer sells the same product with two different names, prices, etc - but on the stock side, **Product 1 (copy)** only exists as a kit of **Product 1** (they're physically the same product)

View File

@@ -0,0 +1,7 @@
* Ooops404 <https://www.ooops404.com/>
* Francesco Foresti <francesco.foresti@ooops404.com>
* Cetmix <https://cetmix.com/>
* Maksim Shurupov

View File

@@ -0,0 +1,3 @@
This module allows to duplicate a product with variants, at the same time creating a BoM with type "Kit" for the new product mapping variants of the original product.
This is useful when managing products that only exist as a "front" for a product with another name, to avoid having to manually map variants in BOM.

View File

@@ -0,0 +1,9 @@
* Open "Product 1" with variants
* Use server action: "Duplicate with attribute match kit"
* A wizard opens up with field "New product template name"
* Inputs name for duplicated product (eg: "Fancy Product 1")
* Click Confirm
A new product is created with name "Fancy Product 1" and a new BOM of type "kit" for this product;
If product does not have variants, when using server action, display error message: "This server action can be used only on products with variants".

View File

@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_product_template_kit_wizard,access.product.template.kit.wizard,model_product_template_kit_wizard,mrp.group_mrp_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_product_template_kit_wizard access.product.template.kit.wizard model_product_template_kit_wizard mrp.group_mrp_user 1 1 1 1

View File

@@ -0,0 +1,451 @@
<?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 Duplicate Kit</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-duplicate-kit">
<h1 class="title">BOM Attribute Match Duplicate Kit</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:799dde4fcb103960a4af12b6bd212c0913ffd0f478293ff3c0fd559245ecae1a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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_duplicate_kit"><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_duplicate_kit"><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&amp;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 allows to duplicate a product with variants, at the same time creating a BoM with type “Kit” for the new product mapping variants of the original product.</p>
<p>This is useful when managing products that only exist as a “front” for a product with another name, to avoid having to manually map variants in BOM.</p>
<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="#usage" id="toc-entry-2">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</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>The use case is that customer sells the same product with two different names, prices, etc - but on the stock side, <strong>Product 1 (copy)</strong> only exists as a kit of <strong>Product 1</strong> (theyre physically the same product)</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<ul class="simple">
<li>Open “Product 1” with variants</li>
<li>Use server action: “Duplicate with attribute match kit”</li>
<li>A wizard opens up with field “New product template name”</li>
<li>Inputs name for duplicated product (eg: “Fancy Product 1”)</li>
<li>Click Confirm</li>
</ul>
<p>A new product is created with name “Fancy Product 1” and a new BOM of type “kit” for this product;</p>
<blockquote>
If product does not have variants, when using server action, display error message: “This server action can be used only on products with variants”.</blockquote>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-3">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_duplicate_kit%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-4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Cetmix</li>
<li>Ooops</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Ooops404 &lt;<a class="reference external" href="https://www.ooops404.com/">https://www.ooops404.com/</a>&gt;<ul>
<li>Francesco Foresti &lt;<a class="reference external" href="mailto:francesco.foresti&#64;ooops404.com">francesco.foresti&#64;ooops404.com</a>&gt;</li>
</ul>
</li>
<li>Cetmix &lt;<a class="reference external" href="https://cetmix.com/">https://cetmix.com/</a>&gt;<ul>
<li>Maksim Shurupov</li>
</ul>
</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">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/aleuffre"><img alt="aleuffre" src="https://github.com/aleuffre.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_duplicate_kit">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

@@ -0,0 +1,2 @@
from . import test_product_template
from . import test_product_template_kit_wizard

View File

@@ -0,0 +1,50 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import Form, SavepointCase
class TestProductTemplateKitCommon(SavepointCase):
@classmethod
def setUpClass(cls):
super(TestProductTemplateKitCommon, cls).setUpClass()
# Attribute Color
cls.attribute_color = cls.env.ref("product.product_attribute_2")
# Attribute Color Values
cls.attribute_color_white = cls.env.ref("product.product_attribute_value_3")
cls.attribute_color_black = cls.env.ref("product.product_attribute_value_4")
# Attribute Legs
cls.attribute_legs = cls.env.ref("product.product_attribute_1")
# Attribute Legs Values
cls.attribute_legs_steel = cls.env.ref("product.product_attribute_value_1")
cls.attribute_legs_aluminium = cls.env.ref("product.product_attribute_value_2")
# Product Without Attributes
cls.product_template_without_attributes = cls.env["product.template"].create(
{"name": "Product Without Attributes"}
)
# Product With One Attribute
form = Form(cls.env["product.template"])
form.name = "Product With One Attribute"
with form.attribute_line_ids.new() as line:
line.attribute_id = cls.attribute_color
line.value_ids.add(cls.attribute_color_white)
line.value_ids.add(cls.attribute_color_black)
cls.product_template_one_attribute = form.save()
# Product With Many Attributes
form = Form(cls.env["product.template"])
form.name = "Product With One Attribute"
with form.attribute_line_ids.new() as line:
line.attribute_id = cls.attribute_color
line.value_ids.add(cls.attribute_color_white)
line.value_ids.add(cls.attribute_color_black)
with form.attribute_line_ids.new() as line:
line.attribute_id = cls.attribute_legs
line.value_ids.add(cls.attribute_legs_steel)
line.value_ids.add(cls.attribute_legs_aluminium)
cls.product_template_two_attributes = form.save()

View File

@@ -0,0 +1,50 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import UserError
from .common import TestProductTemplateKitCommon
class TestProductTemplate(TestProductTemplateKitCommon):
def test_action_duplicate_attribute_match_kit_invalid(self):
"""
Test flow that catch an error when call
action_duplicate_attribute_match_kit function
for product without variants
"""
with self.assertRaises(UserError):
self.product_template_without_attributes.action_duplicate_with_kit()
def test_action_duplicate_attribute_match_Kit_valid(self):
"""
Test flow that returned wizard action, if product
has attributes
"""
product = self.product_template_one_attribute
self.assertEqual(
product.product_variant_count,
2,
"Product attribute variants count must be equal to 2",
)
action = product.action_duplicate_with_kit()
self.assertIsInstance(action, dict, msg="Returned object must be dict")
self.assertEqual(
action["res_model"],
"product.template.kit.wizard",
"Res model must be equal to 'product.template.kit.wizard'",
)
context = action["context"]
self.assertIsInstance(context, dict, "Context must be dict")
self.assertEqual(
context["default_product_tmpl_id"],
product.id,
"Default product template id must be equal to ID {}".format(product.id),
)
self.assertEqual(
context["default_new_product_template_name"],
product.name + " 1",
"Default New product template name must be equal to '{} 1'".format(
product.name
),
)

View File

@@ -0,0 +1,77 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import UserError
from odoo.tests import Form
from .common import TestProductTemplateKitCommon
class TestProductTemplateKitWizard(TestProductTemplateKitCommon):
def test_action_confirm_invalid(self):
"""
Test flow that catch error when product template name
and new product template name is the same
"""
context = {
"default_product_tmpl_id": self.product_template_one_attribute.id,
}
form = Form(self.env["product.template.kit.wizard"].with_context(**context))
form.new_product_template_name = self.product_template_one_attribute.name
wizard = form.save()
with self.assertRaises(UserError):
wizard.action_confirm()
def test_action_confirm_flow(self):
"""Test flow that run full workflow"""
product = self.product_template_two_attributes
context = {
"default_product_tmpl_id": product.id,
"default_new_product_template_name": "{} 1".format(product.name),
}
wizard = Form(
self.env["product.template.kit.wizard"].with_context(**context)
).save()
action = wizard.action_confirm()
self.assertIsInstance(action, dict, "Action must be dict")
new_product_name = "{} 1".format(product.name)
self.assertEqual(
action["name"],
new_product_name,
"Action name must be equal to {}".format(new_product_name),
)
self.assertTrue(action.get("res_id"), "Res ID key must be exists")
product_tmpl = self.env["product.template"].browse(action["res_id"])
self.assertEqual(product_tmpl.name, new_product_name, "Names must be the same")
boms = product_tmpl.bom_ids
self.assertTrue(boms, "BOM's must be exists")
self.assertEqual(len(boms), 1, "Count BOM's must be equal to 1")
self.assertEqual(
boms.product_tmpl_id.id,
product_tmpl.id,
"BOMs product and new product must be the same",
)
self.assertEqual(boms.type, "phantom")
self.assertEqual(boms.product_qty, 1, "Product Qty must be equal to 1")
self.assertTrue(boms.bom_line_ids, "BOM must have Lines")
self.assertEqual(len(boms.bom_line_ids), 1, msg="BOM must have one line")
line = boms.bom_line_ids
self.assertEqual(
line.component_template_id.id,
product.id,
"Component product template ID must be equal to ID {}".format(product.id),
)
self.assertListEqual(
line.match_on_attribute_ids.ids,
[self.attribute_legs.id, self.attribute_color.id],
"Attributes must be the same",
)
self.assertEqual(line.product_qty, 1, "Product Qty must be equal to 1")

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="action_duplicate_attribute_match_kit" model="ir.actions.server">
<field name="name">Duplicate with attribute match kit</field>
<field name="model_id" ref="product.model_product_template" />
<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_duplicate_with_kit()
</field>
</record>
</odoo>

View File

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

View File

@@ -0,0 +1,54 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, fields, models
class ProductTemplateKitWizard(models.TransientModel):
_name = "product.template.kit.wizard"
_description = "Duplicate with attribute match kit"
product_tmpl_id = fields.Many2one(comodel_name="product.template", required=True)
new_product_template_name = fields.Char(required=True)
def action_confirm(self):
"""Duplicate product with bom"""
if self.product_tmpl_id.name == self.new_product_template_name:
raise models.UserError(
_("The name of the new product template should not be the same name")
)
new_product = self.product_tmpl_id.copy(
default={"name": self.new_product_template_name}
)
self.env["mrp.bom"].create(
{
"product_tmpl_id": new_product.id,
"type": "phantom",
"product_qty": 1,
"bom_line_ids": [
(
0,
0,
{
"component_template_id": self.product_tmpl_id.id,
"match_on_attribute_ids": [
(
6,
0,
self.product_tmpl_id.attribute_line_ids.mapped(
"attribute_id"
).ids,
)
],
},
)
],
}
)
return {
"type": "ir.actions.act_window",
"name": self.new_product_template_name,
"view_mode": "form",
"res_model": "product.template",
"res_id": new_product.id,
}

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="product_template_kit_wizard" model="ir.ui.view">
<field name="name">product.template.kit.wizard</field>
<field name="model">product.template.kit.wizard</field>
<field name="arch" type="xml">
<form string="Duplicate with attribute match kit">
<group>
<field name="product_tmpl_id" invisible="1" />
<field name="new_product_template_name" />
</group>
<footer>
<button
name="action_confirm"
string="Confirm"
type="object"
class="oe_highlight"
/>
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
</odoo>