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

[15.0][ADD] product_variant_template_reassign: New module #373

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from

Conversation

chienandalu
Copy link
Member

@chienandalu chienandalu commented Nov 5, 2024

cc @Tecnativa TT51495

ready for review @carlosdauden @pedrobaeza

@chienandalu chienandalu force-pushed the 15.0-add-product_variant_template_reassign branch 3 times, most recently from b333364 to 5ceb0cb Compare November 5, 2024 16:20
@pedrobaeza pedrobaeza added this to the 15.0 milestone Nov 5, 2024
"product.template",
self.origin_product_template_id.ids,
self.target_product_template_id.id,
method="sql",
Copy link
Member

Choose a reason for hiding this comment

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

With method="sql", the possible default_code in the unique variant is lost, as well as other data. One possibility is to specify the merge options.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, done. Although with products with operations like done stock moves normally isn't possible

Copy link
Member

Choose a reason for hiding this comment

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

Well, I was not talking about changing the merge method, but adding the extra parameters to indicate the field merge options.

Copy link
Member Author

Choose a reason for hiding this comment

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

Understood. I added a hook method to configure it and added a test case. Do know of other possible issues of that kind?

Copy link
Member

Choose a reason for hiding this comment

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

The image and list price.

Copy link
Member Author

Choose a reason for hiding this comment

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

I should try for image. As for pricelist_id, its related to the template... what should we do there?

Copy link
Member

Choose a reason for hiding this comment

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

Don't do anything on the list price then.

Copy link
Member Author

Choose a reason for hiding this comment

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

I understood pricelist_id which is related indeed. list_price should be kept and it's done so now. A special post-process hook has been added to deal with field specs that don't work with merge_records

@chienandalu chienandalu force-pushed the 15.0-add-product_variant_template_reassign branch 4 times, most recently from 91398a1 to 85e35e5 Compare November 6, 2024 09:01
"product.template",
self.origin_product_template_id.ids,
self.target_product_template_id.id,
method="sql",
Copy link
Member

Choose a reason for hiding this comment

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

The image and list price.

@chienandalu chienandalu force-pushed the 15.0-add-product_variant_template_reassign branch 2 times, most recently from 6b88490 to 0ae17f7 Compare November 6, 2024 16:30
"author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["chienandalu"],
"license": "AGPL-3",
"depends": ["purchase_stock", "website_sale_stock"],
Copy link
Member

Choose a reason for hiding this comment

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

You have forgotten this again.

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry... 😵‍💫️

Copy link
Member

Choose a reason for hiding this comment

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

This again...

@chienandalu chienandalu force-pushed the 15.0-add-product_variant_template_reassign branch from 0ae17f7 to 5d42634 Compare November 6, 2024 16:33
@chienandalu
Copy link
Member Author

@carlosdauden can you review

@chienandalu chienandalu force-pushed the 15.0-add-product_variant_template_reassign branch from 5d42634 to c49b2c9 Compare November 8, 2024 12:07
).unlink()
# Take a snapshot of the original variant data before the merge
original_values = (
self.origin_product_template_id.product_variant_id.copy_data()
Copy link
Member

Choose a reason for hiding this comment

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

Why not using read instead?

@chienandalu chienandalu force-pushed the 15.0-add-product_variant_template_reassign branch from c49b2c9 to 8d7a869 Compare November 8, 2024 12:55
@lmignon
Copy link
Contributor

lmignon commented Nov 13, 2024

I was thinking of doing the same kind of addon in V16 and I found your PR.

There is, however, one element in the approach that questions me. Why does attaching the variant to another template involve creating a new variant and then merging the existing variant into this new variant? Naively I thought I'd do this first step by simply changing the parent_id in DB and managing the attributes between the variant and the template in the same process. As for template management, my idea was also to update all the FKs to the original template with the value of the target template and thereafter remove-it.

I haven't yet really analyzed all the impacts and functional elements linked to the template and there are undoubtedly many challenges to be met. For example, supplier information should be linked to the variants when the reference is updated from the old template to the new .

@chienandalu
Copy link
Member Author

Hi, @lmignon

Why does attaching the variant to another template involve creating a new variant and then merging the existing variant into this new variant? Naively I thought I'd do this first step by simply changing the parent_id in DB and managing the attributes between the variant and the template in the same process. As for template management, my idea was also to update all the FKs to the original template with the value of the target template and thereafter remove-it.

The main goal of the approach is using the power openupgradelib.merge_records to avoid dealing with the major part of all that stuff. It isn't exempt of pitfalls as we want to preserve the origin variant data and merge_records doesn't have the rules to deal with it sometimes... Maybe we should improve the tool to simplify this module...

I haven't yet really analyzed all the impacts and functional elements linked to the template and there are undoubtedly many challenges to be met. For example, supplier information should be linked to the variants when the reference is updated from the old template to the new.

Yes, in cases like that one we could be missing some of the bussiness logic and we should deal with it.

@lmignon
Copy link
Contributor

lmignon commented Nov 14, 2024

Thank you for your explanation @chienandalu

My main concern with this approach is the impact on the database. With the creation and merge of the old variant to a new one, the process will imply the update of a too large number of records into too many tables. This will lead for sure to concurrent update errors and deadlock on systems daily managing thousands of stock pickings, sale orders etc, making this functionality unusable (you should also take into account all the stock.move.line, sale.order.line, stock.move and sock.move.line existing into your db where the variant is referenced). In my case, it's the biggest challenge. That's why I'm thinking to an approach with the less impact on the database. If we don't create a new variant, we drastically reduce the impact and will speed up the process.... The merge of the template is also possible but do we really need-it. All we need is to be able to use the logic of swapping the original template id with the new one into all the column where a FK exists.

@pedrobaeza
Copy link
Member

There are a lot of submodels and some tricky fields like product_combination which should be properly set for the variant, so that's why we merge the old one into the existing variant, for not having to care too much on each version about internals, and also to avoid non trivial issues "swapping" the real variant. The downside is what you commented, but they are done in SQL, and at the end, this is for correcting an exceptional situation, so it should be done knowing what implies.

@lmignon
Copy link
Contributor

lmignon commented Nov 14, 2024

Thank you @pedrobaeza. My use case is to move from an installation where the variant were not used at all to a full support of the variants. This process will involve a lot of reassignment of variants to others template. This process must be possible on a running instance as part of the day to day work. That's why I will go for the less intrusive approach. An sql update on the table stock_move, stock_move_line, account_move_line, .. is not possible without locking the system. For example, we've 9 986 501 records into the account_move_line table. I'm conscious that the change on the product_combination field will be tricky but if the functionality always ends with a concurrent update error or blocks the normal flow of operations in the company it will be unusable and i will stay with my challenge. Your approach seems pragmatic by reusing very useful/powerfull code of the openupgrade lib. Nevertheless I've the feeling that the indent of openupgradelib is not to be used on a running instance but as part of a migration/update/installation process. That doesn't mean that some part of the code can't be used into normal methods but we have to keep in mind that the need to work properly in an environment with many parallel tasks has not been taken into account in the development of this library. (Maybe I'm wrong...)

@chienandalu chienandalu force-pushed the 15.0-add-product_variant_template_reassign branch from 8d7a869 to a098c28 Compare November 14, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants