Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export class BaseProductAttribute extends Component {
"allSelectedValues",
];

setup() {
super.setup(...arguments);
this.pos = usePos();
}

getFormatPriceExtra(val) {
const sign = val < 0 ? "- " : "+ ";
return sign + this.env.utils.formatCurrency(Math.abs(val));
Expand Down Expand Up @@ -51,6 +56,7 @@ export class MultiProductAttribute extends BaseProductAttribute {
static props = [...BaseProductAttribute.props, "selected?", "customValue?"];

setup() {
super.setup(...arguments);
this.state = useState({
is_value_selected: this.props.attribute.values().reduce((acc, value) => {
acc[value.id] = this.props.selected?.includes(value) || false;
Expand Down Expand Up @@ -141,7 +147,7 @@ export class ProductConfiguratorPopup extends Component {

let combination;
while ((combination = getNext()) !== null) {
if (!combination.some((value) => value.doHaveConflictWith(combination))) {
if (!combination.some((value) => this.pos.doHaveConflictWith(value, combination))) {
combination.forEach((value) => {
const forceVariant = this.props.forceVariantValue
? Object.values(this.props.forceVariantValue).find(
Expand Down Expand Up @@ -234,7 +240,9 @@ export class ProductConfiguratorPopup extends Component {
}

isValidCombination() {
return !this.selectedValues.some((value) => value.doHaveConflictWith(this.selectedValues));
return !this.selectedValues.some((value) =>
this.pos.doHaveConflictWith(value, this.selectedValues)
);
}

get title() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
type="radio"
t-att-checked="value.id === props.selected.id"
t-on-change="() => props.setSelected(value)"
t-att-disabled="pos.doHaveConflictWith(value, props.allSelectedValues)"
t-att-name="value.attribute_id.id"
t-attf-id="{{ value.attribute_id.id }}_{{ value.id }}"
class="form-check-input radio-check"
/>
<label t-attf-for="{{ value.attribute_id.id }}_{{ value.id }}">
<span t-att-class="{ 'text-muted': value.doHaveConflictWith(props.allSelectedValues) }" t-esc="value.name"/>
<span t-att-class="{ 'text-muted': pos.doHaveConflictWith(value, props.allSelectedValues) }" t-esc="value.name"/>
<div t-if="value.price_extra" class="price-extra-cell d-inline-block ms-2">
<span class="price_extra px-2 py-1 rounded-pill text-bg-info">
<t t-esc="getFormatPriceExtra(value.price_extra)"/>
Expand All @@ -35,20 +36,21 @@
<div class="configurator_radio" t-ref="root">
<div class="d-flex flex-wrap gap-2">
<t t-foreach="props.attribute.values()" t-as="value" t-key="value.id">
<div class="attribute-name-cell" t-att-class="{'ptav-not-available': value.excluded}">
<div class="attribute-name-cell">
<input
type="radio"
t-att-checked="value.id === props.selected.id"
t-on-change="() => props.setSelected(value)"
t-att-name="value.attribute_id.id"
t-attf-id="{{ value.attribute_id.id }}_{{ value.id }}"
t-att-disabled="pos.doHaveConflictWith(value, props.allSelectedValues)"
class="form-check-input d-none"
/>
<label
t-attf-class="btn btn-secondary btn-lg lh-lg d-flex {{ value.id == props.selected.id ? 'active' : '' }}"
t-att-name="value.name"
t-attf-for="{{ value.attribute_id.id }}_{{ value.id }}">
<span t-att-class="{ 'text-muted': value.doHaveConflictWith(props.allSelectedValues) }" t-esc="value.name"/>
<span t-att-class="{ 'text-muted': pos.doHaveConflictWith(value, props.allSelectedValues) }" t-esc="value.name"/>
<div t-if="value.price_extra" class="price-extra-cell d-inline-block ms-2">
<span class="price_extra px-2 py-1 rounded-pill text-bg-info">
<t t-esc="getFormatPriceExtra(value.price_extra)"/>
Expand All @@ -70,7 +72,7 @@

<select class="configurator_select form-select form-select-md" t-on-change="(e) => this.onChange(e)">
<t t-foreach="props.attribute.values()" t-as="value" t-key="value.id">
<option t-att-value="value.id" t-att-class="{'ptav-not-available': value.excluded}" t-att-selected="props.selected?.id === value.id ? 'selected' : ''">
<option t-att-value="value.id" t-att-disabled="pos.doHaveConflictWith(value, props.allSelectedValues)" t-att-selected="props.selected?.id === value.id ? 'selected' : ''">
<t t-set="is_custom" t-value="is_custom || (value.is_custom and value.id == props.selected.id)"/>
<t t-esc="value.name"/>
<t t-if="value.price_extra">
Expand Down Expand Up @@ -103,6 +105,7 @@
t-on-change="() => props.setSelected(value)"
t-att-name="value.attribute_id.id"
t-attf-id="{{ value.attribute_id.id }}_{{ value.id }}"
t-att-disabled="pos.doHaveConflictWith(value, props.allSelectedValues)"
class="m-2 opacity-0"
/>
</label>
Expand Down Expand Up @@ -133,7 +136,7 @@
t-attf-class="form-check-label btn btn-secondary btn-lg lh-lg d-flex {{ this.state.is_value_selected[value.id] === true ? 'active' : '' }}"
t-attf-name="multi-{{value.id}}"
t-attf-for="multi-{{value.id}}">
<span t-att-class="{ 'text-muted': value.doHaveConflictWith(props.allSelectedValues) }" t-esc="value.name"/>
<span t-att-class="{ 'text-muted': pos.doHaveConflictWith(value, props.allSelectedValues) }" t-esc="value.name"/>
<div t-if="value.price_extra" class="price-extra-cell d-inline-block ms-2">
<span class="price_extra px-2 py-1 rounded-pill text-bg-info">
<t t-esc="getFormatPriceExtra(value.price_extra)"/>
Expand Down Expand Up @@ -169,7 +172,7 @@
/>
</label>
<div class="text-center mt-2 small">
<span t-att-class="{ 'text-muted': value.doHaveConflictWith(props.allSelectedValues) }"
<span t-att-class="{ 'text-muted': pos.doHaveConflictWith(value, props.allSelectedValues) }"
t-esc="value.name"/>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@ import { Base } from "./related_models";

export class ProductTemplateAttributeValue extends Base {
static pythonModel = "product.template.attribute.value";

get exclusions() {
const values = this.models["product.template.attribute.value"].filter((value) =>
value.excluded_value_ids.some(({ id }) => id === this.id)
);

return [...this.excluded_value_ids, ...values];
}

doHaveConflictWith(values) {
const excludedIds = values.map(({ id }) => id);
return this.exclusions.some(({ id }) => excludedIds.includes(id));
}
}

registry
Expand Down
40 changes: 40 additions & 0 deletions addons/point_of_sale/static/src/app/services/pos_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,43 @@ export class PosStore extends WithLazyGetterTrap {
products[i].available_in_pos = false;
}
}

this.productAttributesExclusion = this.computeProductAttributesExclusion();
}

computeProductAttributesExclusion(ptav_ids = false) {
const exclusions = this.productAttributesExclusion || new Map();

const addExclusion = (key, value) => {
if (!exclusions.has(key)) {
exclusions.set(key, new Set());
}
exclusions.get(key).add(value);
};

for (const ptav of ptav_ids || this.models["product.template.attribute.value"].getAll()) {
const excluded_value_ids = ptav.excluded_value_ids;
const ptavId = ptav.id;
for (const { id: valueId } of excluded_value_ids) {
addExclusion(ptavId, valueId);
addExclusion(valueId, ptavId);
}
}
return exclusions;
}

doHaveConflictWith(value, selectedValues) {
const exclusions = this.productAttributesExclusion.get(value.id);
if (!exclusions) {
return false;
}
const selectedValueIds = new Set(selectedValues.map((v) => v.id));
for (const exclusionId of exclusions) {
if (selectedValueIds.has(exclusionId)) {
return true;
}
}
return false;
}

async onDeleteOrder(order) {
Expand Down Expand Up @@ -600,6 +637,9 @@ export class PosStore extends WithLazyGetterTrap {
{},
false
);
this.productAttributesExclusion = this.computeProductAttributesExclusion(
result["product.template.attribute.value"]
);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const test_pricelists_in_pos_steps = [
},
},
ProductConfigurator.pickRadio("BIG"),
ProductConfigurator.pickRadio("GREEN"),
ProductConfigurator.isUnavailable("RED"),
Dialog.confirm(),
ProductScreen.clickPayButton(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,12 @@ registry.category("web_tour.tours").add("test_cross_exclusion_attribute_values",
Dialog.confirm("Open Register"),
ProductScreen.clickDisplayedProduct("Test Product 1"),
ProductConfigurator.pickRadio("attribute_1_value_1"),
ProductConfigurator.pickRadio("attribute_2_value_1"),
ProductConfigurator.isAddDisabled(),
ProductConfigurator.isRadioDisabled("attribute_2_value_1"),
ProductConfigurator.pickRadio("attribute_2_value_2"),
ProductConfigurator.pickRadio("attribute_1_value_2"),
ProductConfigurator.isAddDisabled(),
ProductConfigurator.isRadioDisabled("attribute_1_value_2"),
ProductConfigurator.pickRadio("attribute_1_value_1"),
ProductConfigurator.pickRadio("attribute_2_value_2"),
ProductConfigurator.isAddEnabled(),
ProductConfigurator.pickRadio("attribute_1_value_2"),
ProductConfigurator.pickRadio("attribute_2_value_1"),
ProductConfigurator.isAddEnabled(),
Chrome.endTour(),
].flat(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,12 @@ export function checkImagePriceExtraVisible(price) {
},
];
}

export function isRadioDisabled(name) {
return [
{
content: `check radio attribute with name ${name}`,
trigger: `.modal .attribute-name-cell:contains('${name}') input:disabled`,
},
];
}
28 changes: 14 additions & 14 deletions addons/point_of_sale/tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,25 @@ def setUpClass(cls):
})
line.product_template_value_ids[0].price_extra = 2

chair_color_attribute = env['product.attribute'].create({
cls.chair_color_attribute = env['product.attribute'].create({
'name': 'Color',
'display_type': 'color',
'create_variant': 'no_variant',
})
chair_color_red = env['product.attribute.value'].create({
cls.chair_color_red = env['product.attribute.value'].create({
'name': 'Red',
'attribute_id': chair_color_attribute.id,
'attribute_id': cls.chair_color_attribute.id,
'html_color': '#ff0000',
})
chair_color_blue = env['product.attribute.value'].create({
'name': 'Blue',
'attribute_id': chair_color_attribute.id,
'attribute_id': cls.chair_color_attribute.id,
'html_color': '#0000ff',
})
chair_color_line = env['product.template.attribute.line'].create({
'product_tmpl_id': cls.configurable_chair.id,
'attribute_id': chair_color_attribute.id,
'value_ids': [(6, 0, [chair_color_red.id, chair_color_blue.id])]
'attribute_id': cls.chair_color_attribute.id,
'value_ids': [(6, 0, [cls.chair_color_red.id, chair_color_blue.id])]
})
chair_color_line.product_template_value_ids[0].price_extra = 1

Expand All @@ -262,28 +262,28 @@ def setUpClass(cls):
'value_ids': [(6, 0, [chair_legs_metal.id, chair_legs_wood.id])]
})

chair_fabrics_attribute = env['product.attribute'].create({
cls.chair_fabrics_attribute = env['product.attribute'].create({
'name': 'Fabrics',
'display_type': 'radio',
'create_variant': 'no_variant',
})
chair_fabrics_leather = env['product.attribute.value'].create({
'name': 'Leather',
'attribute_id': chair_fabrics_attribute.id,
'attribute_id': cls.chair_fabrics_attribute.id,
})
chair_fabrics_wool = env['product.attribute.value'].create({
cls.chair_fabrics_wool = env['product.attribute.value'].create({
'name': 'wool',
'attribute_id': chair_fabrics_attribute.id,
'attribute_id': cls.chair_fabrics_attribute.id,
})
chair_fabrics_other = env['product.attribute.value'].create({
cls.chair_fabrics_other = env['product.attribute.value'].create({
'name': 'Other',
'attribute_id': chair_fabrics_attribute.id,
'attribute_id': cls.chair_fabrics_attribute.id,
'is_custom': True,
})
env['product.template.attribute.line'].create({
'product_tmpl_id': cls.configurable_chair.id,
'attribute_id': chair_fabrics_attribute.id,
'value_ids': [(6, 0, [chair_fabrics_leather.id, chair_fabrics_wool.id, chair_fabrics_other.id])]
'attribute_id': cls.chair_fabrics_attribute.id,
'value_ids': [(6, 0, [chair_fabrics_leather.id, cls.chair_fabrics_wool.id, cls.chair_fabrics_other.id])]
})
chair_color_line.product_template_value_ids[1].is_custom = True

Expand Down