Skip to content

Commit

Permalink
[MIG][17.0] product_configurator_sale:Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bizzappdev committed Nov 13, 2024
1 parent 8e92fdf commit a9085f2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion product_configurator_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Product Configurator Sale",
"version": "16.0.1.0.1",
"version": "17.0.1.0.0",
"category": "Generic Modules/Sale",
"summary": "Product configuration interface modules for Sale",
"author": "Pledra, Odoo Community Association (OCA)",
Expand Down
2 changes: 1 addition & 1 deletion product_configurator_sale/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

# from . import test_sale
from . import test_sale
from . import test_sale_order_line
22 changes: 18 additions & 4 deletions product_configurator_sale/tests/test_sale.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
from odoo.addons.product_configurator.tests import (
test_product_configurator_test_cases as TC,
common as TC,
)


class SaleOrder(TC.ProductConfiguratorTestCases):
def setUp(self):
super(SaleOrder, self).setUp()
self.SaleOrderId = self.env["sale.order"]
super().setUp()
self.SaleOrder = self.env["sale.order"]
self.productPricelist = self.env["product.pricelist"]
self.resPartner = self.env.ref("product_configurator_sale.partenr_sale_1")
self.currency_id = self.env.ref("base.USD")
self.ProductConfWizard = self.env["product.configurator.sale"]

self.config_product = self.env.ref("product_configurator.bmw_2_series")

def test_00_reconfigure_product(self):
product_id = self.env["product.product"].create(
{"product_tmpl_id": self.config_product.id, "name": "Test Product"}
)
pricelist_id = self.productPricelist.create(
{
"name": "Test Pricelist",
"currency_id": self.currency_id.id,
}
)
sale_order_id = self.SaleOrderId.create(
sale_order_id = self.SaleOrder.create(
{
"partner_id": self.resPartner.id,
"partner_invoice_id": self.resPartner.id,
"partner_shipping_id": self.resPartner.id,
"pricelist_id": pricelist_id.id,
"order_line": [
(
0,
0,
{
"product_id": product_id.id,
},
)
],
}
)
context = dict(
Expand Down
4 changes: 3 additions & 1 deletion product_configurator_sale/tests/test_sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def _configure_wizard(self, wizard, template_values):
return wizard.action_config_done()

def _configure_product(self, sale_order, product_template, template_values):
"""Configure `product_template` in `sale_order` with values `template_values`."""
"""
Configure `product_template` in `sale_order` with values `template_values`.
"""
wizard = self._create_wizard(sale_order, product_template)

return self._configure_wizard(wizard, template_values)
Expand Down
8 changes: 4 additions & 4 deletions product_configurator_sale/views/sale_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class="oe_highlight"
groups="product_configurator.group_product_configurator"
name="action_config_start"
states="draft,sent"
invisible="state not in ['draft','sent']"
string="Configure Product"
style="margin-top: 15px;"
type="object"
Expand All @@ -20,16 +20,16 @@
expr="//field[@name='order_line']/form//field[@name='product_id']"
position="after"
>
<field invisible="1" name="config_ok" />
<field column_invisible="1" name="config_ok" />
<field name="config_session_id" />
</xpath>
<xpath
expr="//field[@name='order_line']/tree//field[@name='product_template_id']"
position="after"
>
<field invisible="1" name="config_ok" />
<field column_invisible="1" name="config_ok" />
<button
attrs="{ 'invisible': [ '|', ('config_ok','=',False), ('state','not in',['draft','sent']) ] }"
invisible="not config_ok or state not in ['draft','sent']"
class="fa-lg"
groups="product_configurator.group_product_configurator"
help="Reconfigure"
Expand Down
16 changes: 12 additions & 4 deletions product_configurator_sale/wizard/product_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _get_order_line_vals(self, product_id):

def action_config_done(self):
"""Parse values and execute final code before closing the wizard"""
res = super(ProductConfiguratorSale, self).action_config_done()
res = super().action_config_done()
if res.get("res_model") == self._name:
return res
model_name = "sale.order.line"
Expand All @@ -37,8 +37,16 @@ def action_config_done(self):
# will not trigger onchange automatically
order_line_obj = self.env[model_name]
cfg_session = self.config_session_id
specs = cfg_session.get_onchange_specifications(model=model_name)
updates = order_line_obj.onchange(line_vals, ["product_id"], specs)
fields_spec = cfg_session.get_onchange_specifications(model=model_name)
# Filter the fields_spec dictionary to keep only the keys present in line_vals.
fields_spec = {
key: val
for key, val in fields_spec.items()
if key in list(line_vals.keys())
}
# Trigger the onchange event for the 'product_id' field, passing in line_vals
# and the filtered fields_spec to update the order line accordingly
updates = order_line_obj.onchange(line_vals, ["product_id"], fields_spec)
values = updates.get("value", {})
values = cfg_session.get_vals_to_write(values=values, model=model_name)
values.update(line_vals)
Expand All @@ -60,7 +68,7 @@ def create(self, vals_list):
vals["custom_value_ids"] = self._get_custom_values(
sale_line.config_session_id
)
return super(ProductConfiguratorSale, self).create(vals_list)
return super().create(vals_list)

def _get_custom_values(self, session):
custom_values = [(5,)] + [
Expand Down

0 comments on commit a9085f2

Please sign in to comment.