Skip to content

Commit c31d6f4

Browse files
[MIG] purchase_variant_configurator: Migration to 18.0
1 parent 9f07545 commit c31d6f4

9 files changed

Lines changed: 75 additions & 142 deletions

File tree

purchase_variant_configurator/README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ Contributors
103103
- David Vidal
104104
- Ernesto Tejeda
105105

106+
- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__
107+
108+
- Bhavesh Heliconia
109+
106110
Maintainers
107111
-----------
108112

purchase_variant_configurator/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"name": "Purchase - Product variants",
88
"summary": "Product variants in purchase management",
9-
"version": "16.0.2.0.0",
9+
"version": "18.0.1.0.0",
1010
"license": "AGPL-3",
1111
"depends": ["purchase", "product_variant_configurator"],
1212
"author": "AvanzOSC, "

purchase_variant_configurator/hooks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
33

44

5-
def assign_product_template(cr, registry):
5+
def assign_product_template(env):
66
"""This post-init-hook will update all existing purchase.order.line"""
7+
8+
cr = env.cr
79
cr.execute(
810
"""
911
UPDATE purchase_order_line AS line

purchase_variant_configurator/models/product_supplierinfo.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ProductSupplierinfo(models.Model):
77
_inherit = "product.supplierinfo"
88

99
@api.model
10-
def search(self, args, offset=0, limit=None, order=None, count=False):
10+
def search(self, args, offset=0, limit=None, order=None):
1111
"""HACK: With NewId, the linked product_tmpl_id won't be a proper interger
1212
that we can use in a search. As we need it to get the proper pricelists
1313
we'll be passing it by context. The propper solution would be to
@@ -28,9 +28,5 @@ def search(self, args, offset=0, limit=None, order=None, count=False):
2828
self.env.context.get("pvc_product_tmpl"),
2929
)
3030
args2.append(arg)
31-
return super().search(
32-
args2, offset=offset, limit=limit, order=order, count=count
33-
)
34-
return super().search(
35-
args, offset=offset, limit=limit, order=order, count=count
36-
)
31+
return super().search(args2, offset=offset, limit=limit, order=order)
32+
return super().search(args, offset=offset, limit=limit, order=order)

purchase_variant_configurator/readme/CONTRIBUTORS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
- Pedro M. Baeza
66
- David Vidal
77
- Ernesto Tejeda
8+
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)
9+
- Bhavesh Heliconia
10+

purchase_variant_configurator/static/description/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
453453
<li>Ernesto Tejeda</li>
454454
</ul>
455455
</li>
456+
<li><a class="reference external" href="https://www.heliconia.io">Heliconia Solutions Pvt. Ltd.</a><ul>
457+
<li>Bhavesh Heliconia</li>
458+
</ul>
459+
</li>
456460
</ul>
457461
</div>
458462
<div class="section" id="maintainers">

purchase_variant_configurator/tests/test_purchase_order.py

Lines changed: 48 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2016 ACSONE SA/NV
22
# Copyright 2024 Tecnativa - Víctor Martínez
33
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
4-
from odoo.tests import Form
4+
from odoo import Command
55

66
from odoo.addons.base.tests.common import BaseCommon
77

@@ -51,12 +51,10 @@ def setUpClass(cls):
5151
"categ_id": cls.category1.id,
5252
"standard_price": 100,
5353
"attribute_line_ids": [
54-
(
55-
0,
56-
0,
54+
Command.create(
5755
{
5856
"attribute_id": cls.attribute1.id,
59-
"value_ids": [(6, 0, [cls.value1.id, cls.value2.id])],
57+
"value_ids": [Command.set([cls.value1.id, cls.value2.id])],
6058
},
6159
)
6260
],
@@ -112,62 +110,6 @@ def test_onchange_product_tmpl_id_01(self):
112110
f"{self.product_template_no.name}\n{self.product_template_no.description_purchase}",
113111
)
114112

115-
def test_onchange_product_tmpl_id_02(self):
116-
order_form = Form(self.env["purchase.order"])
117-
order_form.partner_id = self.supplier
118-
with order_form.order_line.new() as line_form:
119-
line_form.product_tmpl_id = self.product_template_yes
120-
order = order_form.save()
121-
line = order.order_line
122-
self.assertFalse(line.product_id)
123-
self.assertIn("Product template 1", line.name)
124-
self.assertIn("Purchase Description", line.name)
125-
self.assertEqual(line.product_uom, self.product_template_yes.uom_id)
126-
self.assertEqual(line.price_unit, 90)
127-
self.assertEqual(line.product_qty, 11)
128-
self.assertTrue(line.date_planned)
129-
order.button_confirm()
130-
self.assertTrue(line.product_id)
131-
self.assertIn("Product template 1", line.name)
132-
self.assertIn("Purchase Description", line.name)
133-
134-
def test_onchange_product_attribute_ids(self):
135-
product = self.product_product.create(
136-
{
137-
"name": "Test product 01",
138-
"product_tmpl_id": self.product_template_yes.id,
139-
"product_attribute_ids": [
140-
(
141-
0,
142-
0,
143-
{
144-
"product_tmpl_id": self.product_template_yes.id,
145-
"attribute_id": self.attribute1.id,
146-
"value_id": self.value1.id,
147-
},
148-
)
149-
],
150-
}
151-
)
152-
order_form = Form(self.env["purchase.order"])
153-
order_form.partner_id = self.supplier
154-
with order_form.order_line.new() as line_form:
155-
line_form.product_tmpl_id = self.product_template_yes
156-
with line_form.product_attribute_ids.edit(0) as pa_form:
157-
pa_form.value_id = self.value1
158-
order = order_form.save()
159-
line = order.order_line
160-
self.assertEqual(line.product_id, product)
161-
expected_domain = [
162-
("product_tmpl_id", "=", self.product_template_yes.id),
163-
(
164-
"product_template_attribute_value_ids",
165-
"=",
166-
product.product_template_attribute_value_ids[0].id,
167-
),
168-
]
169-
self.assertEqual(line.product_id_configurator_domain, expected_domain)
170-
171113
def test_can_create_product_variant(self):
172114
line = self.purchase_order_line.new(
173115
{
@@ -197,33 +139,6 @@ def test_can_create_product_variant(self):
197139
self.assertTrue(line.product_id)
198140
self.assertFalse(line.create_product_variant)
199141

200-
def test_onchange_product_id(self):
201-
product = self.product_product.create(
202-
{
203-
"name": "Test product 02",
204-
"product_tmpl_id": self.product_template_yes.id,
205-
"product_attribute_ids": [
206-
(
207-
0,
208-
0,
209-
{
210-
"product_tmpl_id": self.product_template_yes.id,
211-
"attribute_id": self.attribute1.id,
212-
"value_id": self.value1.id,
213-
},
214-
)
215-
],
216-
}
217-
)
218-
order_form = Form(self.env["purchase.order"])
219-
order_form.partner_id = self.supplier
220-
with order_form.order_line.new() as line_form:
221-
line_form.product_id = product
222-
order = order_form.save()
223-
line = order.order_line
224-
self.assertEqual(len(line.product_attribute_ids), 1)
225-
self.assertEqual(line.product_tmpl_id, self.product_template_yes)
226-
227142
def test_button_confirm_01(self):
228143
order = self.purchase_order.create({"partner_id": self.supplier.id})
229144
line_1 = self.purchase_order_line.new(
@@ -235,9 +150,7 @@ def test_button_confirm_01(self):
235150
"date_planned": "2016-01-01",
236151
"product_uom": self.product_template_yes.uom_id.id,
237152
"product_attribute_ids": [
238-
(
239-
0,
240-
0,
153+
Command.create(
241154
{
242155
"product_tmpl_id": self.product_template_yes.id,
243156
"attribute_id": self.attribute1.id,
@@ -282,37 +195,48 @@ def test_button_confirm_01(self):
282195
"All purchase lines must have a product",
283196
)
284197

285-
def test_button_confirm_02(self):
286-
order_form = Form(self.env["purchase.order"])
287-
order_form.partner_id = self.supplier
288-
with order_form.order_line.new() as line_form:
289-
line_form.product_tmpl_id = self.product_template_yes
290-
with line_form.product_attribute_ids.edit(0) as pa_form:
291-
pa_form.value_id = self.value1
292-
order = order_form.save()
293-
line1 = order.order_line
294-
self.assertFalse(line1.product_id)
295-
order.button_confirm()
296-
self.assertTrue(line1.product_id)
297-
purchase = Form(order)
298-
with purchase.order_line.new() as line_form:
299-
line_form.product_tmpl_id = self.product_template_yes
300-
with line_form.product_attribute_ids.edit(0) as pa_form:
301-
pa_form.value_id = self.value2
302-
purchase.save()
303-
line2 = order.order_line - line1
304-
self.assertTrue(line2.product_id)
305-
self.assertNotEqual(line1.product_id, line2.product_id)
198+
def test_compute_product_id_is_required(self):
199+
# Set the company configuration to True
200+
self.env.company.po_confirm_create_variant = True
201+
line = self.purchase_order_line.new(
202+
{
203+
"product_tmpl_id": self.product_template_yes.id,
204+
"product_uom": self.product_template_yes.uom_id.id,
205+
"product_qty": 5,
206+
"company_id": self.env.company.id, # Explicitly set the company
207+
}
208+
)
209+
line._compute_product_id_is_required()
210+
self.assertFalse(
211+
line.product_id_is_required,
212+
"Product ID should not be required when po_confirm_create_variant is True.",
213+
)
214+
215+
# Set the company configuration to False
216+
self.env.company.po_confirm_create_variant = False
217+
line._compute_product_id_is_required()
218+
self.assertTrue(
219+
line.product_id_is_required,
220+
"Product ID should be required when po_confirm_create_variant is False.",
221+
)
222+
223+
def test_create_purchase_order_line_with_variant_creation(self):
224+
# Create a purchase order in 'purchase' state
225+
order = self.purchase_order.create({"partner_id": self.supplier.id})
226+
order.button_confirm() # Move the order to 'purchase' state
306227

307-
def test_copy(self):
308-
old_date = "2017-01-01"
309-
order_form = Form(self.env["purchase.order"])
310-
order_form.partner_id = self.supplier
311-
with order_form.order_line.new() as line_form:
312-
line_form.product_tmpl_id = self.product_template_yes
313-
line_form.date_planned = old_date
314-
with line_form.product_attribute_ids.edit(0) as pa_form:
315-
pa_form.value_id = self.value1
316-
order = order_form.save()
317-
new_order = order.copy()
318-
self.assertNotEqual(new_order.order_line.date_planned, old_date)
228+
# Create a line without a product but with a product template
229+
line_vals = {
230+
"order_id": order.id,
231+
"product_tmpl_id": self.product_template_yes.id,
232+
"product_uom": self.product_template_yes.uom_id.id,
233+
"product_qty": 1,
234+
"name": "Line with variant creation",
235+
"date_planned": "2024-01-01",
236+
}
237+
line = self.purchase_order_line.create([line_vals])
238+
239+
# Ensure a product was created
240+
self.assertTrue(
241+
line.product_id, "Product variant should be created for the line."
242+
)

purchase_variant_configurator/views/inherited_purchase_order_views.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<field name="inherit_id" ref="purchase.purchase_order_form" />
77
<field name="priority" eval="20" />
88
<field name="arch" type="xml">
9-
<xpath expr="//field[@name='order_line']/tree" position="attributes">
9+
<xpath expr="//field[@name='order_line']/list" position="attributes">
1010
<!-- force using the form -->
1111
<attribute name="editable" />
1212
</xpath>
@@ -28,9 +28,9 @@
2828
nolabel="1"
2929
colspan="2"
3030
>
31-
<tree create="0" delete="0" editable="1">
32-
<field name="owner_model" invisible="1" />
33-
<field name="owner_id" invisible="1" />
31+
<list create="0" delete="0" editable="bottom">
32+
<!-- <field name="owner_model" invisible="1" />-->
33+
<!-- <field name="owner_id" invisible="1" />-->
3434
<field name="attribute_id" force_save="1" />
3535
<field
3636
name="possible_value_ids"
@@ -42,7 +42,7 @@
4242
name="value_id"
4343
context="{'show_attribute': False, 'default_attribute_id': attribute_id, 'template_for_attribute_value': product_tmpl_id}"
4444
/>
45-
</tree>
45+
</list>
4646
</field>
4747
<field name="can_create_product" invisible="1" />
4848
<field
@@ -76,7 +76,7 @@
7676
<field name="product_id_configurator_domain" invisible="1" />
7777
</xpath>
7878
<xpath
79-
expr="//field[@name='order_line']/tree//field[@name='product_id']"
79+
expr="//field[@name='order_line']/list//field[@name='product_id']"
8080
position="before"
8181
>
8282
<field
@@ -85,14 +85,14 @@
8585
/>
8686
</xpath>
8787
<xpath
88-
expr="//field[@name='order_line']/tree//field[@name='product_id']"
88+
expr="//field[@name='order_line']/list//field[@name='product_id']"
8989
position="after"
9090
>
9191
<field name="product_id_configurator_domain" invisible="1" />
9292
<field name="product_id_is_required" invisible="1" />
9393
</xpath>
9494
<xpath
95-
expr="//field[@name='order_line']/tree//field[@name='product_id']"
95+
expr="//field[@name='order_line']/list//field[@name='product_id']"
9696
position="attributes"
9797
>
9898
<attribute name="domain">product_id_configurator_domain</attribute>

purchase_variant_configurator/views/res_config_settings_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
ref="purchase.res_config_settings_view_form_purchase"
88
/>
99
<field name="arch" type="xml">
10-
<xpath expr="//div[@data-key='purchase']" position="inside">
10+
<xpath expr="//app[@name='purchase']" position="inside">
1111
<h2>Product configurator</h2>
1212
<div
1313
class="row mt16 o_settings_container"

0 commit comments

Comments
 (0)