Skip to content

Commit

Permalink
Merge PR #141 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by simahawk
  • Loading branch information
OCA-git-bot committed Nov 27, 2024
2 parents 548dd4a + e78af0c commit 9a19f68
Show file tree
Hide file tree
Showing 28 changed files with 477 additions and 449 deletions.
3 changes: 0 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^product_configurator/|
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
^setup/|/static/description/index\.html$|
# We don't want to mess with tool-generated files
Expand Down
24 changes: 12 additions & 12 deletions product_configurator/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ 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/16.0/product_configurator
:target: https://github.com/OCA/product-configurator/tree/17.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-16-0/product-configurator-16-0-product_configurator
:target: https://translation.odoo-community.org/projects/product-configurator-17-0/product-configurator-17-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=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-configurator&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module has all the mechanics to support product configuration. It serves as a base
dependency for configuration interfaces.
This module has all the mechanics to support product configuration. It
serves as a base dependency for configuration interfaces.

**Table of contents**

Expand All @@ -42,27 +42,27 @@ 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:%2016.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:%2017.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
~~~~~~~
-------

* Pledra

Contributors
~~~~~~~~~~~~
------------

* `Aion Tech <https://aiontech.company/>`_:
- `Aion Tech <https://aiontech.company/>`__:

* Simone Rubino <[email protected]>
- Simone Rubino <[email protected]>

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -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/16.0/product_configurator>`_ project on GitHub.
This module is part of the `OCA/product-configurator <https://github.com/OCA/product-configurator/tree/17.0/product_configurator>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
10 changes: 5 additions & 5 deletions product_configurator/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Product Configurator",
"version": "16.0.1.1.1",
"version": "17.0.1.0.0",
"category": "Generic Modules/Base",
"summary": "Base for product configuration interface modules",
"author": "Pledra, Odoo Community Association (OCA)",
Expand Down Expand Up @@ -28,10 +28,11 @@
"assets": {
"web.assets_backend": [
"/product_configurator/static/src/scss/form_widget.scss",
"/product_configurator/static/src/js/form_widgets.js",
"/product_configurator/static/src/js/form_widgets.esm.js",
"/product_configurator/static/src/js/boolean_button_widget.esm.js",
"/product_configurator/static/src/js/boolean_button_widget.xml",
"/product_configurator/static/src/js/relational_fields.js",
"/product_configurator/static/src/js/kanban_widgets.esm.js",
"/product_configurator/static/src/js/list_widgest.esm.js",
]
},
"demo": [
Expand All @@ -44,10 +45,9 @@
],
"images": ["static/description/cover.png"],
"post_init_hook": "post_init_hook",
"qweb": ["static/xml/create_button.xml"],
"development_status": "Beta",
"maintainers": ["PCatinean"],
"installable": False,
"installable": True,
"application": True,
"auto_install": False,
}
4 changes: 2 additions & 2 deletions product_configurator/init_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
logger = logging.getLogger(__name__)


def post_init_hook(cr, registry):
def post_init_hook(env):
"""Transfer existing weight values to weight_dummy after installation
since now the weight field is computed
"""
cr.execute("UPDATE product_product SET weight_dummy = weight")
env.cr.execute("UPDATE product_product SET weight_dummy = weight")
2 changes: 1 addition & 1 deletion product_configurator/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _check_default_value_domains(self):
"generate an invalid configuration.\
\n%s"
)
% (exc.name)
% (exc.args[0])
) from exc

def toggle_config(self):
Expand Down
29 changes: 10 additions & 19 deletions product_configurator/models/product_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,30 +302,21 @@ def get_attribute_value_extra_prices(
extra_prices[attr_val_id.id] += line.price_extra
return extra_prices

def name_get(self):
res = super().name_get()
def _compute_display_name(self):
# useless return to make pylint happy
res = super()._compute_display_name()
if not self.env.context.get("show_price_extra"):
return res
product_template_id = self.env.context.get("active_id", False)

price_precision = self.env["decimal.precision"].precision_get("Product Price")
extra_prices = self.get_attribute_value_extra_prices(
product_tmpl_id=product_template_id, pt_attr_value_ids=self
)

res_prices = []
for val in res:
price_extra = extra_prices.get(val[0])
for attribute in self:
extra_prices = attribute.get_attribute_value_extra_prices(
product_tmpl_id=product_template_id, pt_attr_value_ids=attribute
)
price_extra = extra_prices.get(attribute.id)
if price_extra:
val = (
val[0],
"{} ( +{} )".format(
val[1],
("{0:,.%sf}" % (price_precision)).format(price_extra),
),
)
res_prices.append(val)
return res_prices
name = f"{attribute.name} ( +{price_extra:.{price_precision}f} )"
attribute.display_name = name

@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
Expand Down
38 changes: 31 additions & 7 deletions product_configurator/models/product_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -540,9 +541,9 @@ def update_session_configuration_value(self, vals, product_tmpl_id=None):
)

custom_val = self.get_custom_value_id()

attr_val_dict = {}
custom_val_dict = {}

for attr_line in product_tmpl_id.attribute_line_ids:
attr_id = attr_line.attribute_id.id
field_name = field_prefix + str(attr_id)
Expand All @@ -553,13 +554,10 @@ def update_session_configuration_value(self, vals, product_tmpl_id=None):

# Add attribute values from the client except custom attribute
# If a custom value is being written, but field name is not in
# the write dictionary, then it must be a custom value!
# the write dictionary, then it must be a custom value!
if vals.get(field_name, custom_val.id) != custom_val.id:
if attr_line.multi and isinstance(vals[field_name], list):
if not vals[field_name]:
field_val = None
else:
field_val = vals[field_name][0][2]
field_val = self._update_field_values(vals, field_name, attr_line)
elif not attr_line.multi and isinstance(vals[field_name], int):
field_val = vals[field_name]
else:
Expand All @@ -582,10 +580,36 @@ def update_session_configuration_value(self, vals, product_tmpl_id=None):
custom_val_dict.update({attr_id: val})
# Ensure there is no standard value stored if we have switched
# from selected value to custom value.
attr_val_dict.update({attr_id: False})
attr_val_dict.update({attr_id: custom_val.id})

self.update_config(attr_val_dict, custom_val_dict)

def _update_field_values(self, vals, field_name, attr_line):
"""New method for update field values for a given attribute."""
final_val = None
if not vals[field_name]:
return final_val
# Retrieve existing values for the attribute
value_ids = self.value_ids.filtered(
lambda value, attr_line=attr_line: value.attribute_id.id
== attr_line.attribute_id.id
)
# Initialize `final_val` with IDs
final_val = value_ids.ids or []

# Process each `field_vals` operation for the current attribute
for field_vals in vals.get(field_name, []):
if field_vals and field_vals[0] == Command.SET:
final_val = list(set(field_vals[2] or []))
elif field_vals and field_vals[0] == Command.LINK:
if field_vals[1] not in final_val:
final_val.append(field_vals[1])
elif field_vals and field_vals[0] in (Command.UNLINK, Command.DELETE):
if field_vals[1] in final_val:
final_val.remove(field_vals[1])

return final_val

def update_config(self, attr_val_dict=None, custom_val_dict=None):
"""Update the session object with the given value_ids and custom values.
Expand Down
3 changes: 3 additions & 0 deletions product_configurator/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions product_configurator/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Aion Tech](https://aiontech.company/):
- Simone Rubino \<<[email protected]>\>
3 changes: 0 additions & 3 deletions product_configurator/readme/CONTRIBUTORS.rst

This file was deleted.

2 changes: 2 additions & 0 deletions product_configurator/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module has all the mechanics to support product configuration. It
serves as a base dependency for configuration interfaces.
2 changes: 0 additions & 2 deletions product_configurator/readme/DESCRIPTION.rst

This file was deleted.

46 changes: 26 additions & 20 deletions product_configurator/static/src/js/boolean_button_widget.esm.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
/** @odoo-module **/
const {onMounted, onRendered, useRef, useState} = owl;
import {BooleanField} from "@web/views/fields/boolean/boolean_field";
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";

export class BooleanButtonField extends BooleanField {
export class BooleanButton extends BooleanField {
static template = "product_configurator.BooleanButtonField";

setup() {
super.setup();
this.state1 = useState({value: 0});
this.root = useRef("root");

onMounted(() => {
this.updateConfigurableButton();
});

onRendered(() => {
this.updateConfigurableButton();
});
}

onChange() {
this.state1.value++;
}

updateConfigurableButton() {
this.text = this.props.value
this.text = this.state.value
? this.props.activeString
: this.props.inactiveString;
this.hover = this.props.value
this.hover = this.state.value
? this.props.inactiveString
: this.props.activeString;
var val_color = this.props.value ? "text-success" : "text-danger";
var hover_color = this.props.value ? "text-danger" : "text-success";

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);

$(this.root.el).empty();
$(this.root.el).append($val).append($hover);
}
}

BooleanButtonField.props = {
BooleanButton.props = {
...standardFieldProps,
activeString: {type: String, optional: true},
activeString: {type: String},
inactiveString: {type: String, optional: true},
};

BooleanButtonField.extractProps = ({attrs}) => {
return {
activeString: attrs.options.active,
inactiveString: attrs.options.inactive,
};
export const BooleanButtonField = {
...booleanField,
component: BooleanButton,
extractProps: ({options}) => {
return {
activeString: options.active,
inactiveString: options.inactive,
};
},
};

BooleanButtonField.template = "product_configurator.BooleanButtonField";
// Register the field component
registry.category("fields").add("boolean_button", BooleanButtonField);
5 changes: 2 additions & 3 deletions product_configurator/static/src/js/boolean_button_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
<templates xml:space="preserve">

<t t-name="product_configurator.BooleanButtonField" owl="1">
<div t-ref="root" t-on-click="onChange">
<div t-ref="root">
<CheckBox
id="props.id"
value="props.value or false"
value="props.state or false"
className="'d-inline-block me-2'"
disabled="isReadonly"
onChange.bind="onChange"
/>
</div>
</t>
Expand Down
22 changes: 22 additions & 0 deletions product_configurator/static/src/js/form_widgets.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* @odoo-module */
import {FormController} from "@web/views/form/form_controller";
import {patch} from "@web/core/utils/patch";

patch(FormController.prototype, {
setup() {
super.setup(...arguments);
if (
this.props.resModel === "product.product" &&
this.props.context.custom_create_variant
) {
this.canCreate = false;
}
},
async beforeExecuteActionButton(clickParams) {
if (clickParams.special === "no_save") {
delete clickParams.special;
return true;
}
return super.beforeExecuteActionButton(...arguments);
},
});
Loading

0 comments on commit 9a19f68

Please sign in to comment.