Skip to content

[13.0][FIX] product: merge product variants with same attributes - #2513

Closed
MiquelRForgeFlow wants to merge 1 commit into
OCA:13.0from
ForgeFlow:13.0-fix-merge-products-with-same-attributes
Closed

MiquelRForgeFlow wants to merge 1 commit into
OCA:13.0from
ForgeFlow:13.0-fix-merge-products-with-same-attributes

Conversation

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor

Make use of merge_records tool to merge records.

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor Author

I can retarget to v11 branch if you prefer.

@kos94ok-3D

Copy link
Copy Markdown

We have not the constrain for combination_indices in pre-migration so maybe better to calculate combination_indices and then group product by product template and combination_indices?

@MiquelRForgeFlow
MiquelRForgeFlow force-pushed the 13.0-fix-merge-products-with-same-attributes branch from e297acb to 29d8bb4 Compare May 17, 2021 13:17
@MiquelRForgeFlow
MiquelRForgeFlow force-pushed the 13.0-fix-merge-products-with-same-attributes branch from 29d8bb4 to a1f3395 Compare June 4, 2021 10:56
@kos94ok-3D

Copy link
Copy Markdown

Hi, @MiquelRForgeFlow Could you rebase it?

@MiquelRForgeFlow
MiquelRForgeFlow force-pushed the 13.0-fix-merge-products-with-same-attributes branch from a1f3395 to c272fd6 Compare November 19, 2021 09:45
@kos94ok-3D

Copy link
Copy Markdown

Maybe need to be added in a commit? odoo/odoo#32086
And said that it was added in Odoo v12 6 months after the release of Odoo v13.

@kos94ok-3D kos94ok-3D left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on a real DB

@pedrobaeza pedrobaeza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you update combination_indices after the merge?

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor Author

Shouldn't you update combination_indices after the merge?

No, why? The combination_indices are the same, they don't change.

for template_id in templates:
openupgrade_merge_records.merge_records(
env, 'product.product', templates[template_id][1:],
templates[template_id][0], field_spec=None, method='sql',

@MiquelRForgeFlow MiquelRForgeFlow Dec 16, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question now is: should I put a field_spec?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends if the standard fields require it or default merge values are enough

@MiquelRForgeFlow MiquelRForgeFlow Dec 17, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my best option is {'default_code': 'first_not_null', 'active': 'or', 'barcode': 'first_not_null', 'volume': 'max', 'weight': 'max'}. My concern is for custom modules that add float/char/boolean fields, which would need to add more things in this dict. Maybe we could add in openupgradelib a functionality like if the dict contains 'other_fields': 'preserve', then every other field is excluded and preserved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrobaeza

Copy link
Copy Markdown
Member

My take on this is that merging complete products is something that shouldn't be corrected at OpenUpgrade level. If they have done such ugly thing, then it must be fixed before doing the migration.

@MiquelRForgeFlow

MiquelRForgeFlow commented Dec 17, 2021 •

Copy link
Copy Markdown
Contributor Author

Ok (don't delete branch)

@cvinh

cvinh commented Mar 16, 2022

Copy link
Copy Markdown

FYI this PR fixed our issue where we have a product with same attributes
@MiquelRForgeFlow thanks for not having deleted it

@eLBati

eLBati commented Oct 28, 2026

Copy link
Copy Markdown
Member

I’d like to draw your attention to this one #6070

pedrobaeza pushed a commit that referenced this pull request Oct 29, 2026
Before odoo/odoo@088edee2ce71 ("[FIX] product: do not create duplicate
variants", odoo/odoo#35013), Odoo 12 reactivated archived variants whose
combination already had an active variant (sell the variants, remove an
attribute from the template, add it again). That fix prevents new
duplicates but doesn't clean the existing ones, so v12 databases can
contain several active variants for the same combination, and the
creation of the product_product_combination_unique index on v13 fails.

Variants without attribute values get an empty combination_indices, as
Odoo computes it, so they are also covered. For each template and
combination, the variant with the lowest ID is kept active and the
others are archived: unlike #2513, no records are merged or deleted.

Assisted-by: Claude Opus 5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants