Skip to content

Commit

Permalink
[IMP]product_configurator:Allow Reset and Back with required fields t…
Browse files Browse the repository at this point in the history
…hat are blank and Configuration Session Search More issues when restrictions are set.
  • Loading branch information
Vandan-OSI committed Jun 6, 2024
1 parent a883bcc commit fb5d191
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 10 deletions.
76 changes: 76 additions & 0 deletions product_configurator/models/product_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,82 @@ def _compute_display_name(self):
)
rec.display_name = name or rec.display_name

Check warning on line 311 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L311

Added line #L311 was not covered by tests

@api.model
def web_search_read(
self, domain, specification, offset=0, limit=None, order=None, count_limit=None
):
"""Use name_search as a domain restriction for the frontend to show
only values set on the product template taking all the configuration
restrictions into account.
TODO: This only works when activating the selection not when typing
"""
if self.env.context.get("wizard_id"):
wiz_id = self.env["product.configurator"].browse(

Check warning on line 324 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L324

Added line #L324 was not covered by tests
self.env.context.get("wizard_id")
)
if (
wiz_id.domain_attr_ids
and self.env.context.get("field_name") == wiz_id.dyn_field_value
):
if self.env.context.get("is_m2m"):
if len(domain) > 2:
vals1 = domain[-1]
vals2 = domain[1]

Check warning on line 334 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L333-L334

Added lines #L333 - L334 were not covered by tests
if vals2 and vals1:
vals = list(set(vals2[2]) - set(vals1[2]))
domain = [("id", "in", vals)]

Check warning on line 337 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L336-L337

Added lines #L336 - L337 were not covered by tests
else:
domain = [("id", "in", wiz_id.domain_attr_ids.ids)]

Check warning on line 339 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L339

Added line #L339 was not covered by tests

elif wiz_id.domain_attr_2_ids and (
self.env.context.get("field_name") == wiz_id.dyn_field_2_value
or not wiz_id.dyn_field_2_value
):
domain = [("id", "in", wiz_id.domain_attr_2_ids.ids)]

Check warning on line 345 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L345

Added line #L345 was not covered by tests

product_tmpl_id = self.env.context.get("_cfg_product_tmpl_id")

Check warning on line 347 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L347

Added line #L347 was not covered by tests
if product_tmpl_id:
# TODO: Avoiding browse here could be a good performance enhancer
product_tmpl = self.env["product.template"].browse(product_tmpl_id)
tmpl_vals = product_tmpl.attribute_line_ids.mapped("value_ids")
attr_restrict_ids = []
preset_val_ids = []
new_args = []

Check warning on line 354 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L350-L354

Added lines #L350 - L354 were not covered by tests
for arg in domain:
# Restrict values only to value_ids set on product_template
if arg[0] == "id" and arg[1] == "not in":
preset_val_ids = arg[2]

Check warning on line 358 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L358

Added line #L358 was not covered by tests
# TODO: Check if all values are available for configuration
else:
new_args.append(arg)
val_ids = set(tmpl_vals.ids)

Check warning on line 362 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L361-L362

Added lines #L361 - L362 were not covered by tests
if preset_val_ids:
val_ids -= set(arg[2])
val_ids = self.env["product.config.session"].values_available(

Check warning on line 365 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L364-L365

Added lines #L364 - L365 were not covered by tests
val_ids, preset_val_ids, product_tmpl_id=product_tmpl_id
)
new_args.append(("id", "in", val_ids))

Check warning on line 368 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L368

Added line #L368 was not covered by tests
mono_tmpl_lines = product_tmpl.attribute_line_ids.filtered(
lambda line: not line.multi
)
for line in mono_tmpl_lines:
line_val_ids = set(line.mapped("value_ids").ids)

Check warning on line 373 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L373

Added line #L373 was not covered by tests
if line_val_ids & set(preset_val_ids):
attr_restrict_ids.append(line.attribute_id.id)

Check warning on line 375 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L375

Added line #L375 was not covered by tests
if attr_restrict_ids:
new_args.append(("attribute_id", "not in", attr_restrict_ids))
domain = new_args
res = super().web_search_read(

Check warning on line 379 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L377-L379

Added lines #L377 - L379 were not covered by tests
domain,
specification,
offset=offset,
limit=limit,
order=order,
count_limit=count_limit,
)
return res

Check warning on line 387 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L387

Added line #L387 was not covered by tests

@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
"""Use name_search as a domain restriction for the frontend to show
Expand Down
15 changes: 7 additions & 8 deletions product_configurator/static/src/js/form_widgets.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ patch(FormController.prototype, {
}
});
},
// Async beforeExecuteActionButton(clickParams) {
// console.log("beforeExecuteActionButton", clickParams);
// if (clickParams.special === "no_save") {
// delete clickParams.special;
// return true;
// }
// return super.beforeExecuteActionButton(...arguments);
// },
async beforeExecuteActionButton(clickParams) {
if (clickParams.special === "no_save") {
delete clickParams.special;
return true;
}
return super.beforeExecuteActionButton(...arguments);
},
});

patch(ListController.prototype, {
Expand Down
4 changes: 2 additions & 2 deletions product_configurator/wizard/product_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,6 @@ def action_next_step(self):
wizard_action = self.with_context(
allow_preset_selection=False
).get_wizard_action(wizard=self)

if not self.product_tmpl_id:
return wizard_action

Expand Down Expand Up @@ -1041,7 +1040,6 @@ def get_wizard_action(self, view_cache=False, wizard=None):
)
if wizard:
ctx.update({"wizard_id": wizard.id, "wizard_id_view_ref": wizard.id})

wizard_action = {
"type": "ir.actions.act_window",
"res_model": self._name,
Expand All @@ -1058,6 +1056,8 @@ def get_wizard_action(self, view_cache=False, wizard=None):
}
if wizard:
wizard_action.update({"res_id": wizard.id})
if self and not self.state:
self.state = "select"

Check warning on line 1060 in product_configurator/wizard/product_configurator.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/wizard/product_configurator.py#L1060

Added line #L1060 was not covered by tests
return wizard_action

def open_step(self, step):
Expand Down
1 change: 1 addition & 0 deletions product_configurator/wizard/product_configurator_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
name="action_reset"
confirm="Are you sure? This will remove your current configuration for this template!"
class="oe_highlight"
special="no_save"
invisible="not product_tmpl_id or state == 'select'"
/>
</header>
Expand Down

0 comments on commit fb5d191

Please sign in to comment.