Skip to content

Commit c6ca146

Browse files
[MIG] sale_variant_configurator: Migration to version 19.0
TT61966
1 parent 8dd4bd4 commit c6ca146

8 files changed

Lines changed: 127 additions & 46 deletions

File tree

sale_variant_configurator/README.rst

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
15
=======================
26
Sale - Product variants
37
=======================
@@ -13,22 +17,25 @@ Sale - Product variants
1317
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
1418
:target: https://odoo-community.org/page/development-status
1519
:alt: Production/Stable
16-
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
1721
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1822
:alt: License: AGPL-3
1923
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--variant-lightgray.png?logo=github
20-
:target: https://github.com/OCA/product-variant/tree/18.0/sale_variant_configurator
24+
:target: https://github.com/OCA/product-variant/tree/19.0/sale_variant_configurator
2125
:alt: OCA/product-variant
2226
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/product-variant-18-0/product-variant-18-0-sale_variant_configurator
27+
:target: https://translation.odoo-community.org/projects/product-variant-19-0/product-variant-19-0-sale_variant_configurator
2428
:alt: Translate me on Weblate
2529
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-variant&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-variant&target_branch=19.0
2731
:alt: Try me on Runboat
2832

2933
|badge1| |badge2| |badge3| |badge4| |badge5|
3034

31-
35+
This module allows you to create the product variant when a sale order
36+
is confirmed. It adds to the sale line a product configurator, so that
37+
selecting a product and its attributes can serve for creating/selecting
38+
the product variant.
3239

3340
**Table of contents**
3441

@@ -41,7 +48,7 @@ Bug Tracker
4148
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-variant/issues>`_.
4249
In case of trouble, please check there if your issue has already been reported.
4350
If you spotted it first, help us to smash it by providing a detailed and welcomed
44-
`feedback <https://github.com/OCA/product-variant/issues/new?body=module:%20sale_variant_configurator%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
51+
`feedback <https://github.com/OCA/product-variant/issues/new?body=module:%20sale_variant_configurator%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
4552

4653
Do not contact contributors directly about support or help with technical issues.
4754

@@ -58,6 +65,14 @@ Authors
5865
Contributors
5966
------------
6067

68+
- Oihane Crucelaegui oihanecrucelaegi@avanzosc.es
69+
- `Tecnativa <https://www.tecnativa.com>`__:
70+
71+
- Pedro M. Baeza
72+
- David Vidal
73+
- Andrii Kompaniiets
74+
75+
- Ana Juaristi ajuaristio@gmail.com
6176
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)
6277

6378
- Bhavesh Heliconia
@@ -75,6 +90,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
7590
mission is to support the collaborative development of Odoo features and
7691
promote its widespread use.
7792

78-
This module is part of the `OCA/product-variant <https://github.com/OCA/product-variant/tree/18.0/sale_variant_configurator>`_ project on GitHub.
93+
This module is part of the `OCA/product-variant <https://github.com/OCA/product-variant/tree/19.0/sale_variant_configurator>`_ project on GitHub.
7994

8095
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

sale_variant_configurator/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "Sale - Product variants",
99
"summary": "Product variants in sale management",
10-
"version": "18.0.1.0.0",
10+
"version": "19.0.1.0.0",
1111
"development_status": "Production/Stable",
1212
"license": "AGPL-3",
1313
"depends": ["sale", "product_variant_configurator"],

sale_variant_configurator/models/sale_order.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
class SaleOrder(models.Model):
1010
_inherit = "sale.order"
1111

12-
def _action_confirm(self):
12+
def action_confirm(self):
1313
"""Create possible product variants not yet created."""
1414
lines_without_product = self.mapped("order_line").filtered(
1515
lambda x: not x.product_id and x.product_tmpl_id
1616
)
1717
for line in lines_without_product:
18-
line.create_variant_if_needed()
19-
return super()._action_confirm()
18+
if bool(line.product_attribute_ids.mapped("value_id")):
19+
line.create_variant_if_needed()
20+
else:
21+
line.product_template_id = line.product_tmpl_id
22+
return super().action_confirm()
2023

2124

2225
class SaleOrderLine(models.Model):
@@ -30,25 +33,19 @@ class SaleOrderLine(models.Model):
3033
related=False,
3134
string="Product Template (no related)",
3235
)
33-
product_id = fields.Many2one(required=False)
3436

35-
_sql_constraints = [
36-
(
37-
"accountable_required_fields",
38-
"CHECK(display_type IS NOT NULL OR "
39-
"((product_id IS NOT NULL OR product_tmpl_id IS NOT NULL) AND "
40-
"product_uom IS NOT NULL))",
41-
"Missing required fields on accountable sale order line.",
42-
),
43-
(
44-
"non_accountable_null_fields",
45-
"CHECK(display_type IS NULL OR "
46-
"(product_id IS NULL AND product_tmpl_id IS NULL AND "
47-
"price_unit = 0 AND product_uom_qty = 0 AND "
48-
"product_uom IS NULL AND customer_lead = 0))",
49-
"Forbidden values on non-accountable sale order line",
50-
),
51-
]
37+
_accountable_required_fields = models.Constraint(
38+
"CHECK(display_type IS NOT NULL OR is_downpayment OR "
39+
"(product_tmpl_id IS NOT NULL OR product_id IS NOT NULL AND "
40+
"product_uom_id IS NOT NULL))",
41+
"Missing required fields on accountable sale order line.",
42+
)
43+
_non_accountable_null_fields = models.Constraint(
44+
"CHECK(display_type IS NULL OR (product_tmpl_id IS NULL AND "
45+
"product_id IS NULL AND price_unit = 0 AND product_uom_qty = 0 "
46+
"AND product_uom_id IS NULL AND customer_lead = 0))",
47+
"Forbidden values on non-accountable sale order line",
48+
)
5249

5350
@api.model_create_multi
5451
def create(self, vals_list):
@@ -78,3 +75,13 @@ def _get_product_description(self, template, product, product_attributes):
7875
def _compute_price_unit(self):
7976
"""Add the proper dependency to compute the price correctly."""
8077
return super()._compute_price_unit()
78+
79+
def _get_sale_order_line_multiline_description_variants(self):
80+
# It needs to correctly show the name of the sale.order.line with attributes
81+
name = super()._get_sale_order_line_multiline_description_variants()
82+
if not self.product_attribute_ids:
83+
return name
84+
for attribute in self.product_attribute_ids:
85+
if attribute.value_id.display_name:
86+
name += "\n" + attribute.value_id.display_name
87+
return name
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
- Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
2+
- [Tecnativa](https://www.tecnativa.com):
3+
- Pedro M. Baeza
4+
- David Vidal
5+
- Andrii Kompaniiets
6+
- Ana Juaristi <ajuaristio@gmail.com>
17
- \[Heliconia Solutions Pvt. Ltd.\](<https://www.heliconia.io>)
28
- Bhavesh Heliconia
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
1+
This module allows you to create the product variant when a sale order
2+
is confirmed. It adds to the sale line a product configurator,
3+
so that selecting a product and its attributes can serve for creating/selecting the product variant.

sale_variant_configurator/static/description/index.html

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>Sale - Product variants</title>
6+
<title>README.rst</title>
77
<style type="text/css">
88

99
/*
@@ -360,16 +360,25 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document" id="sale-product-variants">
364-
<h1 class="title">Sale - Product variants</h1>
363+
<div class="document">
365364

365+
366+
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367+
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368+
</a>
369+
<div class="section" id="sale-product-variants">
370+
<h1>Sale - Product variants</h1>
366371
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
367372
!! This file is generated by oca-gen-addon-readme !!
368373
!! changes will be overwritten. !!
369374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370375
!! source digest: sha256:967bca3a7e441cfaf105a13a9d73ed4e07faf7af4692d93d0de454830ae76e69
371376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.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/product-variant/tree/18.0/sale_variant_configurator"><img alt="OCA/product-variant" src="https://img.shields.io/badge/github-OCA%2Fproduct--variant-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-variant-18-0/product-variant-18-0-sale_variant_configurator"><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/product-variant&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.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/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-variant/tree/19.0/sale_variant_configurator"><img alt="OCA/product-variant" src="https://img.shields.io/badge/github-OCA%2Fproduct--variant-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-variant-19-0/product-variant-19-0-sale_variant_configurator"><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/product-variant&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378+
<p>This module allows you to create the product variant when a sale order
379+
is confirmed. It adds to the sale line a product configurator, so that
380+
selecting a product and its attributes can serve for creating/selecting
381+
the product variant.</p>
373382
<p><strong>Table of contents</strong></p>
374383
<div class="contents local topic" id="contents">
375384
<ul class="simple">
@@ -383,45 +392,54 @@ <h1 class="title">Sale - Product variants</h1>
383392
</ul>
384393
</div>
385394
<div class="section" id="bug-tracker">
386-
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
395+
<h2><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h2>
387396
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/product-variant/issues">GitHub Issues</a>.
388397
In case of trouble, please check there if your issue has already been reported.
389398
If you spotted it first, help us to smash it by providing a detailed and welcomed
390-
<a class="reference external" href="https://github.com/OCA/product-variant/issues/new?body=module:%20sale_variant_configurator%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
399+
<a class="reference external" href="https://github.com/OCA/product-variant/issues/new?body=module:%20sale_variant_configurator%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
391400
<p>Do not contact contributors directly about support or help with technical issues.</p>
392401
</div>
393402
<div class="section" id="credits">
394-
<h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
403+
<h2><a class="toc-backref" href="#toc-entry-2">Credits</a></h2>
395404
<div class="section" id="authors">
396-
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
405+
<h3><a class="toc-backref" href="#toc-entry-3">Authors</a></h3>
397406
<ul class="simple">
398407
<li>OdooMRP team</li>
399408
<li>AvanzOSC</li>
400409
<li>Tecnativa</li>
401410
</ul>
402411
</div>
403412
<div class="section" id="contributors">
404-
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
413+
<h3><a class="toc-backref" href="#toc-entry-4">Contributors</a></h3>
405414
<ul class="simple">
415+
<li>Oihane Crucelaegui <a class="reference external" href="mailto:oihanecrucelaegi&#64;avanzosc.es">oihanecrucelaegi&#64;avanzosc.es</a></li>
416+
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
417+
<li>Pedro M. Baeza</li>
418+
<li>David Vidal</li>
419+
<li>Andrii Kompaniiets</li>
420+
</ul>
421+
</li>
422+
<li>Ana Juaristi <a class="reference external" href="mailto:ajuaristio&#64;gmail.com">ajuaristio&#64;gmail.com</a></li>
406423
<li>[Heliconia Solutions Pvt. Ltd.](<a class="reference external" href="https://www.heliconia.io">https://www.heliconia.io</a>)<ul>
407424
<li>Bhavesh Heliconia</li>
408425
</ul>
409426
</li>
410427
</ul>
411428
</div>
412429
<div class="section" id="maintainers">
413-
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
430+
<h3><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h3>
414431
<p>This module is maintained by the OCA.</p>
415432
<a class="reference external image-reference" href="https://odoo-community.org">
416433
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
417434
</a>
418435
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
419436
mission is to support the collaborative development of Odoo features and
420437
promote its widespread use.</p>
421-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-variant/tree/18.0/sale_variant_configurator">OCA/product-variant</a> project on GitHub.</p>
438+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-variant/tree/19.0/sale_variant_configurator">OCA/product-variant</a> project on GitHub.</p>
422439
<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>
423440
</div>
424441
</div>
425442
</div>
443+
</div>
426444
</body>
427445
</html>

sale_variant_configurator/tests/test_sale_order.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_onchange_product_tmpl_id(self):
7777
"name": "Line 1",
7878
"product_tmpl_id": self.product_template_yes.id,
7979
"price_unit": 100,
80-
"product_uom": self.product_template_yes.uom_id.id,
80+
"product_uom_id": self.product_template_yes.uom_id.id,
8181
"product_uom_qty": 1,
8282
}
8383
)
@@ -135,7 +135,7 @@ def _test_can_create_product_variant(self):
135135
"product_tmpl_id": self.product_template_yes.id,
136136
"price_unit": 100,
137137
"name": "Line 1",
138-
"product_uom": self.product_template_yes.uom_id.id,
138+
"product_uom_id": self.product_template_yes.uom_id.id,
139139
}
140140
)
141141
self.assertFalse(line.can_create_product)
@@ -182,7 +182,7 @@ def test_onchange_product_id(self):
182182
"price_unit": 100,
183183
"name": "Line 1",
184184
"product_uom_qty": 1,
185-
"product_uom": product.uom_id.id,
185+
"product_uom_id": product.uom_id.id,
186186
},
187187
)
188188
],
@@ -203,7 +203,7 @@ def _test_action_confirm(self):
203203
"price_unit": 100,
204204
"name": "Line 1",
205205
"product_uom_qty": 1,
206-
"product_uom": self.product_template_yes.uom_id.id,
206+
"product_uom_id": self.product_template_yes.uom_id.id,
207207
"product_attribute_ids": [
208208
Command.create(
209209
{
@@ -221,7 +221,7 @@ def _test_action_confirm(self):
221221
{
222222
"order_id": order.id,
223223
"product_tmpl_id": self.product_template_no.id,
224-
"product_uom": self.product_template_no.uom_id.id,
224+
"product_uom_id": self.product_template_no.uom_id.id,
225225
"product_uom_qty": 1,
226226
"price_unit": 200,
227227
"name": "Line 2",

sale_variant_configurator/views/sale_view.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,39 @@
6969
</list>
7070
</field>
7171
</xpath>
72+
<xpath
73+
expr="//field[@name='order_line']/list//field[@name='product_id']"
74+
position="attributes"
75+
>
76+
<attribute name="required">0</attribute>
77+
</xpath>
78+
79+
<xpath
80+
expr="//field[@name='order_line']/list//field[@name='product_uom_id']"
81+
position="attributes"
82+
>
83+
<attribute name="required">0</attribute>
84+
</xpath>
85+
<xpath
86+
expr="//field[@name='order_line']/list//field[@name='product_template_id']"
87+
position="attributes"
88+
>
89+
<attribute name="required">0</attribute>
90+
</xpath>
91+
<!-- Order line form / popup -->
92+
<xpath
93+
expr="//field[@name='order_line']/form//field[@name='product_id']"
94+
position="attributes"
95+
>
96+
<attribute name="required">0</attribute>
97+
</xpath>
98+
99+
<xpath
100+
expr="//field[@name='order_line']/form//field[@name='product_uom_id']"
101+
position="attributes"
102+
>
103+
<attribute name="required">0</attribute>
104+
</xpath>
72105
</field>
73106
</record>
74107
<record model="ir.ui.view" id="view_order_line_tree">

0 commit comments

Comments
 (0)