Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][MIG] product_variant_change_attribute_value: Migration to 18.0 #377

Open
wants to merge 26 commits into
base: 18.0
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c1aefca
[13.0][ADD] product_variant_change_attribute_value
TDu Apr 29, 2021
281e3be
product_variant_change_attribute_value: cleanup
simahawk Aug 5, 2021
8185937
product_variant_change_attribute_value: reorganize code
simahawk Aug 5, 2021
95850e5
product_variant_change_attribute_value: fix test load
simahawk Aug 5, 2021
caa3f40
product_variant_change_attribute_value: misc code imp
simahawk Aug 5, 2021
bde99ff
product_variant_change_attribute_value: convert act_window rec
simahawk Aug 6, 2021
583caa9
product_variant_change_attribute_value: tests mute logger
simahawk Aug 6, 2021
dda4a69
product_variant_change_attribute_value: clean all vals by att at once
simahawk Aug 6, 2021
e558e04
product_variant_change_attribute_value: add test for delete all values
simahawk Aug 6, 2021
115da49
product_variant_change_attribute_value: order actions, handle ondelet…
simahawk Aug 6, 2021
47aab6c
product_variant_change_attribute_value: handle delete all
simahawk Aug 6, 2021
66f501f
product_variant_change_attribute_value: add attr filter
simahawk Aug 9, 2021
d086aa8
product_variant_change_attribute_value: improve tests
simahawk Aug 9, 2021
90fcf44
product_variant_change_attribute_value: add README placeholder
simahawk Aug 9, 2021
7f530d7
product_variant_change_attribute_value: fix perf
simahawk Aug 12, 2021
a56a3fb
product_variant_change_attribute_value: add ROADMAP
simahawk Aug 12, 2021
2206775
product_variant_change_attribute_value: improve view
simahawk Aug 12, 2021
905ce62
product_variant_change_attribute_value: fix tests
simahawk Aug 13, 2021
9655b66
product_variant_change_attribute_value: fix tests
simahawk Aug 16, 2021
eb0b039
product_variant_change_attribute_value: cleanup + speed improvement
mmequignon Dec 1, 2021
42e8ed9
product_variant_change_attribute_value: prevent product combination c…
mmequignon Dec 1, 2021
b10e8da
product_variant_change_attribute_valu: black, isort, prettier
mmequignon Jan 5, 2022
798776f
mig product_variant_change_attribute_value
mmequignon Jan 5, 2022
dea304e
[IMP] add feature remove all attributes
Jan 11, 2022
7616f9a
[IMP] product_variant_change_attribute_value: pre-commit auto fixes
Kimkhoi3010 Dec 3, 2024
077f3ba
[MIG] product_variant_change_attribute_value: Migration to 18.0
Kimkhoi3010 Dec 3, 2024
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
Prev Previous commit
Next Next commit
product_variant_change_attribute_value: cleanup
simahawk authored and Kimkhoi3010 committed Dec 2, 2024
commit 281e3be8d16f7cc584fc11a16e0186f0cb109516
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ def test_remove_attribute_value(self):

wiz = self.wizard.with_context(default_res_ids=self.variants).create({})
self._change_action(wiz, self.steel, "delete")
wiz.action_change_attributes()
wiz.action_apply()

self.assertFalse(self.is_value_on_variant(self.variant_1, self.steel))
self.assertFalse(
@@ -92,7 +92,7 @@ def test_change_attribure_value(self):

wiz = self.wizard.with_context(default_res_ids=self.variants).create({})
self._change_action(wiz, self.white, "replace", self.pink)
wiz.action_change_attributes()
wiz.action_apply()

self.assertFalse(self.is_value_on_variant(self.variant_1, self.white))
self.assertTrue(self.is_value_on_variant(self.variant_1, self.pink))
@@ -115,7 +115,7 @@ def test_change_attribute_value_2(self):
default_res_ids=[self.variant_3.id, self.variant_4.id]
).create({})
self._change_action(wiz, self.white, "replace", self.pink)
wiz.action_change_attributes()
wiz.action_apply()

self.assertFalse(self.is_value_on_variant(self.variant_3, self.white))
self.assertFalse(self.is_value_on_variant(self.variant_4, self.white))
@@ -142,12 +142,12 @@ def test_active_deactivate_attribute_value_2_step(self):
)
wiz = self.wizard.with_context(default_res_ids=self.variants).create({})
self._change_action(wiz, self.white, "replace", self.pink)
wiz.action_change_attributes()
wiz.action_apply()
self.assertFalse(
self._is_attribute_value_on_template(self.variant_1, self.white)
)
self._change_action(wiz, self.black, "replace", self.white)
wiz.action_change_attributes()
wiz.action_apply()
self.assertTrue(
self._is_attribute_value_on_template(self.variant_1, self.white)
)
@@ -165,7 +165,7 @@ def test_active_deactivate_attribute_value_1_step(self):
wiz = self.wizard.with_context(default_res_ids=self.variants).create({})
self._change_action(wiz, self.white, "replace", self.pink)
self._change_action(wiz, self.black, "replace", self.white)
wiz.action_change_attributes()
wiz.action_apply()
self.assertTrue(
self._is_attribute_value_on_template(self.variant_1, self.white)
)
Original file line number Diff line number Diff line change
@@ -8,31 +8,32 @@ class ProductVariantAttributeValueAction(models.TransientModel):
_name = "variant.attribute.value.action"
_description = "Wizard action to do on variant attribute value"

def _get_attribute_action_list(self):
return [
("delete", "Delete"),
("replace", "Replace"),
("do_nothing", "Do Nothing"),
]

product_attribute_value_id = fields.Many2one("product.attribute.value",)
product_attribute_value_id = fields.Many2one(comodel_name="product.attribute.value")
attribute_action = fields.Selection(
selection="_get_attribute_action_list", default="do_nothing", required=True,
selection="_selection_action", default="do_nothing", required=True,
)
attribute_id = fields.Many2one(
"product.attribute",
comodel_name="product.attribute",
related="product_attribute_value_id.attribute_id",
readonly=True,
)
selectable_attribute_value_ids = fields.Many2many(
"product.attribute.value", compute="_compute_selectable_attribute_value_ids"
comodel_name="product.attribute.value",
compute="_compute_selectable_attribute_value_ids",
)
replaced_by_id = fields.Many2one(
"product.attribute.value",
comodel_name="product.attribute.value",
string="Replace with",
domain="[('id', 'in', selectable_attribute_value_ids)]",
)

def _selection_action(self):
return [
("do_nothing", "Do Nothing"),
("replace", "Replace"),
("delete", "Delete"),
]

@api.depends("attribute_action")
def _compute_selectable_attribute_value_ids(self):
for rec in self:
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ class VariantAttributeValueWizard(models.TransientModel):
product_variant_count = fields.Integer(compute="_compute_count")
product_template_count = fields.Integer(compute="_compute_count")
attributes_action_ids = fields.Many2many(
"variant.attribute.value.action",
comodel_name="variant.attribute.value.action",
relation="variant_attribute_wizard_attribute_action_rel",
default=lambda self: self._default_attributes_action_ids(),
)
@@ -47,9 +47,9 @@ def _compute_count(self):
record.product_ids.mapped("product_tmpl_id")
)

def action_change_attributes(self):
def action_apply(self):
for product in self.product_ids:
self.update_variant_value(product)
self._action_apply(product)

def _is_attribute_value_being_used(self, variant_id, attribute_value):
"""Check if attribute value is still used by a variant."""
@@ -64,12 +64,12 @@ def _is_attribute_value_being_used(self, variant_id, attribute_value):
)
return attribute_value in existing_attributes

def update_variant_value(self, product_id):
def _action_apply(self, product):
"""Update a variant with all the actions set by the user in the wizard."""
TplAttrLine = self.env["product.template.attribute.line"]
TplAttrValue = self.env["product.template.attribute.value"]
template = product_id.product_tmpl_id
pav_ids = product_id.product_template_attribute_value_ids.mapped(
template = product.product_tmpl_id
pav_ids = product.product_template_attribute_value_ids.mapped(
"product_attribute_value_id"
)
for value_action in self.attributes_action_ids:
@@ -120,14 +120,14 @@ def update_variant_value(self, product_id):
}
)
# Update the values set on the product variant
ptav_ids = product_id.product_template_attribute_value_ids.filtered(
ptav_ids = product.product_template_attribute_value_ids.filtered(
lambda r: r.product_attribute_value_id != pav
)
if action == "replace":
ptav_ids |= tpl_attr_value
product_id.product_template_attribute_value_ids = ptav_ids
product.product_template_attribute_value_ids = ptav_ids
# Remove the changed value from the template attribute line if needed
if not self._is_attribute_value_being_used(product_id, pav):
if not self._is_attribute_value_being_used(product, pav):
tpl_attr_line = template.attribute_line_ids.filtered(
lambda l: l.attribute_id == pav.attribute_id
)
Original file line number Diff line number Diff line change
@@ -60,8 +60,8 @@
</notebook>
<footer>
<button
name="action_change_attributes"
string="Save"
name="action_apply"
string="Apply"
type="object"
class="btn-primary"
/>