Skip to content

Commit

Permalink
[MIG] product_configurator: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bizzappdev committed Feb 13, 2025
1 parent f74a867 commit 5bf3c75
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 93 deletions.
10 changes: 5 additions & 5 deletions product_configurator/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Product Configurator
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--configurator-lightgray.png?logo=github
:target: https://github.com/OCA/product-configurator/tree/17.0/product_configurator
:target: https://github.com/OCA/product-configurator/tree/18.0/product_configurator
:alt: OCA/product-configurator
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-configurator-17-0/product-configurator-17-0-product_configurator
:target: https://translation.odoo-community.org/projects/product-configurator-18-0/product-configurator-18-0-product_configurator
: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/product-configurator&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-configurator&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -42,7 +42,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-configurator/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/product-configurator/issues/new?body=module:%20product_configurator%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/product-configurator/issues/new?body=module:%20product_configurator%0Aversion:%2018.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.

Expand Down Expand Up @@ -82,6 +82,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-PCatinean|

This module is part of the `OCA/product-configurator <https://github.com/OCA/product-configurator/tree/17.0/product_configurator>`_ project on GitHub.
This module is part of the `OCA/product-configurator <https://github.com/OCA/product-configurator/tree/18.0/product_configurator>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion product_configurator/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Product Configurator",
"version": "17.0.1.0.1",
"version": "18.0.1.0.0",
"category": "Generic Modules/Base",
"summary": "Base for product configuration interface modules",
"author": "Pledra, Odoo Community Association (OCA)",
Expand Down
10 changes: 5 additions & 5 deletions product_configurator/data/menu_configurable_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<field name="name">Configurable Templates</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.template</field>
<field name="view_mode">kanban,tree,form</field>
<field name="view_mode">kanban,list,form</field>
<field name="view_id" ref="product.product_template_kanban_view" />
<field
name="context"
Expand All @@ -42,7 +42,7 @@
<field name="name">Configured Variants</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.product</field>
<field name="view_mode">kanban,form,tree</field>
<field name="view_mode">kanban,form,list</field>
<field name="search_view_id" ref="product.product_search_form_view" />
<field name="view_id" eval="False" />
<!-- Force empty -->
Expand Down Expand Up @@ -88,7 +88,7 @@
<field name="name">Configuration Steps</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.config.step</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
</record>

<menuitem
Expand All @@ -103,7 +103,7 @@
<field name="name">Configuration Restrictions</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.config.domain</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
</record>

<menuitem
Expand All @@ -118,7 +118,7 @@
<field name="name">Configuration Sessions</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.config.session</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
</record>

<menuitem
Expand Down
25 changes: 15 additions & 10 deletions product_configurator/models/product_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging
from ast import literal_eval
from itertools import chain

from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.fields import Command
from odoo.tools.misc import flatten, formatLang
from odoo.tools.misc import formatLang

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -421,7 +422,10 @@ def get_cfg_weight(self, value_ids=None, custom_vals=None):

self = self.with_context(active_id=product_tmpl.id)

value_ids = flatten(value_ids)
# Use the updated flatten method (using itertools.chain)
value_ids = list(
chain.from_iterable(v if isinstance(v, list) else [v] for v in value_ids)
)

weight_extra = 0.0
product_attr_val_obj = self.env["product.template.attribute.value"]
Expand Down Expand Up @@ -504,8 +508,6 @@ def _compute_currency_id(self):
product_preset_id = fields.Many2one(
comodel_name="product.product",
string="Preset",
domain="[('product_tmpl_id', '=', product_tmpl_id),\
('config_preset_ok', '=', True)]",
)

def action_confirm(self, product_id=None):
Expand Down Expand Up @@ -1009,9 +1011,7 @@ def get_next_step(

adjacent_steps = self.get_adjacent_steps()
next_step = adjacent_steps.get("next_step")
open_step_lines = list(
map(lambda x: "%s" % (x), self.get_open_step_lines().ids)
)
open_step_lines = list(map(lambda x: f"{x}", self.get_open_step_lines().ids))

session_config_step = self.config_step
if (
Expand Down Expand Up @@ -1173,7 +1173,7 @@ def check_and_open_incomplete_step(self, value_ids=None, custom_value_ids=None):
step_to_open = step
break
if step_to_open:
return "%s" % (step_to_open.id)
return f"{step_to_open.id}"
return False

@api.model
Expand Down Expand Up @@ -1529,7 +1529,12 @@ def flatten_val_ids(self, value_ids):
:param value_ids: list of value ids or mix of ids and list of ids
(e.g: [1, 2, 3, [4, 5, 6]])
:returns: flattened list of ids ([1, 2, 3, 4, 5, 6])"""
flat_val_ids = set(flatten(value_ids))
if not isinstance(value_ids, list):
return [value_ids] # Ensure single values are wrapped in a list

Check warning on line 1533 in product_configurator/models/product_config.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_config.py#L1533

Added line #L1533 was not covered by tests

flat_val_ids = set(
chain.from_iterable(v if isinstance(v, list) else [v] for v in value_ids)
)
return list(flat_val_ids)

def formatPrices(self, prices=None, dp="Product Price"):
Expand Down Expand Up @@ -1632,7 +1637,7 @@ def _compute_val_name(self):
uom = attr_val_custom.attribute_id.uom_id.name
attr_val_custom.name = "{}{}".format(
attr_val_custom.value,
(" %s" % uom) or "",
f" {uom}" if uom else "",
)

name = fields.Char(readonly=True, compute="_compute_val_name", store=True)
Expand Down
27 changes: 17 additions & 10 deletions product_configurator/static/src/js/boolean_button_widget.esm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/** @odoo-module **/
/* @odoo-module */
import {BooleanField, booleanField} from "@web/views/fields/boolean/boolean_field";
import {onMounted, onRendered, useRef} from "@odoo/owl";
import {registry} from "@web/core/registry";
import {standardFieldProps} from "@web/views/fields/standard_field_props";
const {document} = globalThis;

export class BooleanButton extends BooleanField {
static template = "product_configurator.BooleanButtonField";
Expand All @@ -21,25 +22,31 @@ export class BooleanButton extends BooleanField {
}

updateConfigurableButton() {
// Clear previous content and append new elements
if (!this.root.el) {
return;
}
this.text = this.state.value
? this.props.activeString
: this.props.inactiveString;
this.hover = this.state.value
? this.props.inactiveString
: this.props.activeString;

var val_color = this.state.value ? "text-success" : "text-danger";
var hover_color = this.state.value ? "text-danger" : "text-success";

var $val = $("<span>")
.addClass("o_stat_text o_boolean_button o_not_hover " + val_color)
.text(this.text);
var $hover = $("<span>")
.addClass("o_stat_text o_boolean_button o_hover d-none " + hover_color)
.text(this.hover);
// Create elements using vanilla JS
const valSpan = document.createElement("span");
valSpan.className = `o_stat_text o_boolean_button o_not_hover ${val_color}`;
valSpan.textContent = this.text;

const hoverSpan = document.createElement("span");
hoverSpan.className = `o_stat_text o_boolean_button o_hover d-none ${hover_color}`;
hoverSpan.textContent = this.hover;

$(this.root.el).empty();
$(this.root.el).append($val).append($hover);
this.root.el.innerHTML = "";
this.root.el.appendChild(valSpan);
this.root.el.appendChild(hoverSpan);
}
}

Expand Down
2 changes: 1 addition & 1 deletion product_configurator/tests/test_configuration_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from odoo import SUPERUSER_ID, Command
from odoo.exceptions import ValidationError
from odoo.fields import first
from odoo.tests.common import Form, TransactionCase
from odoo.tests import Form, TransactionCase
from odoo.tools.safe_eval import safe_eval


Expand Down
9 changes: 3 additions & 6 deletions product_configurator/views/product_attribute_view.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Product Attributes -->

<record id="product_attribute_tree_view" model="ir.ui.view">
<field name="name">product.config.product.attribute.tree</field>
<field name="model">product.attribute</field>
Expand Down Expand Up @@ -83,7 +82,7 @@
<field name="name">Attributes</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.attribute</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
<field name="context">{'flag_config_ok': True}</field>
</record>

Expand All @@ -96,7 +95,6 @@
/>

<!-- Product Attribute Value -->

<record
id="product_template_attribute_value_view_tree_weight_extra"
model="ir.ui.view"
Expand All @@ -109,7 +107,7 @@
name="inherit_id"
ref="product.product_template_attribute_value_view_tree"
/>
<field name="type">tree</field>
<field name="type">list</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='price_extra']" position="after">
<field
Expand Down Expand Up @@ -144,7 +142,6 @@
</record>

<!-- Product Attribute Value -->

<record id="product_attribute_value_list" model="ir.ui.view">
<field name="name">product.attribute.value.list.inherit</field>
<field name="model">product.attribute.value</field>
Expand Down Expand Up @@ -190,7 +187,7 @@
<field name="name">Attribute Values</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.attribute.value</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
</record>

<menuitem
Expand Down
22 changes: 10 additions & 12 deletions product_configurator/views/product_config_view.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Configuration Steps -->

<record id="config_step_form_view" model="ir.ui.view">
<field name="name">product.configurator.config.step.form</field>
<field name="model">product.config.step</field>
Expand All @@ -23,15 +22,14 @@
<field name="model">product.config.step</field>
<field name="arch" type="xml">
<form string="Configuration Step">
<tree name="name">
<list name="name">
<field name="name" />
</tree>
</list>
</form>
</field>
</record>

<!-- Configuration Restrictions -->

<record id="product_config_domain_form_view" model="ir.ui.view">
<field name="name">product.configurator.domain.form</field>
<field name="model">product.config.domain</field>
Expand All @@ -45,7 +43,7 @@
<notebook>
<page string="Rules">
<field name="domain_line_ids">
<tree editable="bottom">
<list editable="bottom">
<field name="sequence" widget="handle" />
<field
name="attribute_id"
Expand All @@ -64,7 +62,7 @@
domain="[('id', 'in', template_attribute_value_ids)]"
/>
<field name="operator" />
</tree>
</list>
</field>
</page>
<page string="Inherited">
Expand All @@ -89,7 +87,7 @@
<notebook>
<page string="Rules">
<field name="domain_line_ids">
<tree editable="bottom">
<list editable="bottom">
<field name="sequence" widget="handle" />

<field
Expand All @@ -110,7 +108,7 @@
domain="[('id', 'in', template_attribute_value_ids)]"
/>
<field name="operator" />
</tree>
</list>
</field>
</page>
<page string="Inherited">
Expand All @@ -125,7 +123,7 @@
<field name="name">product.config.session.tree</field>
<field name="model">product.config.session</field>
<field name="arch" type="xml">
<tree create="false">
<list create="false">
<field name="name" />
<field name="product_tmpl_id" />
<field name="value_ids" widget="many2many_tags" />
Expand All @@ -140,7 +138,7 @@
<field name="config_step_name" />
<field name="product_id" />
<field name="state" />
</tree>
</list>
</field>
</record>

Expand Down Expand Up @@ -174,14 +172,14 @@
<notebook>
<page name="custom_vals" string="Custom Values">
<field name="custom_value_ids">
<tree editable="bottom">
<list editable="bottom">
<field name="attribute_id" />
<field name="value" />
<field
name="attachment_ids"
widget="many2many_tags"
/>
</tree>
</list>
</field>
</page>
</notebook>
Expand Down
Loading

0 comments on commit 5bf3c75

Please sign in to comment.