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

[12.0][FIX] fix product.template related fields #173

Open
wants to merge 4 commits into
base: 12.0
Choose a base branch
from

Conversation

huguesdk
Copy link

make product.template.product_variant_id a stored computed field to avoid the following error when setting the print_category_id or to_print related fields:

non-stored field product.template.product_variant_id cannot be searched.

make product.template.product_variant_id a stored computed field to
avoid the following error when setting the print_category_id or to_print
related fields: "non-stored field product.template.product_variant_id
cannot be searched."
@legalsylvain legalsylvain added this to the 12.0 milestone Dec 3, 2023
@legalsylvain
Copy link
Member

Hello @huguesdk ! Je vais laisser la PR ouverte. la cible c'est désormais la V16, ou j'ai mis le module dans l'OCA.
ça joue ?
https://github.com/OCA/product-attribute/tree/16.0/product_print_category#product---print-categories

Copy link

codecov bot commented Dec 3, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6e3c82c) 85.62% compared to head (a00f0c6) 85.62%.
Report is 7 commits behind head on 12.0.

Additional details and impacted files
@@           Coverage Diff           @@
##             12.0     #173   +/-   ##
=======================================
  Coverage   85.62%   85.62%           
=======================================
  Files         149      149           
  Lines        2330     2331    +1     
  Branches      360      360           
=======================================
+ Hits         1995     1996    +1     
  Misses        266      266           
  Partials       69       69           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@huguesdk
Copy link
Author

huguesdk commented Dec 7, 2023

ok, fine for me. i’ll test and create a similar pr for version 16 on the oca repo then.

…id for inactive templates

Signed-off-by: Carmen Bianca BAKKER <[email protected]>
@carmenbianca carmenbianca force-pushed the 12.0-fix-product_print_category_product_template_related_fields branch from 93ce600 to 589b6b4 Compare September 27, 2024 13:08
@carmenbianca
Copy link
Contributor

@huguesdk added a patch to your code, internal task T12969

@carmenbianca
Copy link
Contributor

i also made a pr here : odoo/odoo#181811

@carmenbianca
Copy link
Contributor

carmenbianca commented Oct 22, 2024

Upstream PR likely won't be merged. I added a new commit d5d7e05 61ae3f8 with a new insight to achieve the same result without overriding the compute method.

Comment on lines 29 to 30
if "active" in vals:
self._compute_product_variant_id()
Copy link
Author

Choose a reason for hiding this comment

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

i don’t understand how this fixes the problem where an archived product template is duplicated and has no variants. _compute_product_variant_id() accesses product_variant_ids, which won’t contain archived variants. or am i missing something?

also, do you know why the test is failing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed the test.

Between trying to upstream this and patching it here, I've also had a wrong assumption about how things work in Odoo 12.

In Odoo 12:

  • When copying a product.template which has product variants, the copied result does NOT have any product variants.

In Odoo 15 (and maybe earlier):

  • When copying a product.template which has product variants, the product.template.attribute.values (PTAVs) from which those product.products were generated are copied. Then, during the create method of the product.template, new product.products are created from those PTAVs.

To answer your question:

Indeed, when a product.template is inactive, _compute_product_variant_id() sets False, because product_variant_ids only contains archived products and will thus be an empty recordset. This appears to be by design, so we match upstream behaviour here.

When a template is (re)activated, instead of reactivating its product variants, new product.products are created from the PTAVs. Then by running our compute method after that has happened, product_variant_id is correctly populated.

But by running that compute method again when the template (and thus its also its variants) is unarchived, we get a sensible result. This matches upstream behaviour precisely.

Copy link
Author

Choose a reason for hiding this comment

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

nicely done, thanks for the explanation!

…pute method

Overriding methods is bad practice. By simply recomputing at the correct
stage in the write method, we achieve effectively the same.

Signed-off-by: Carmen Bianca BAKKER <[email protected]>
@carmenbianca carmenbianca force-pushed the 12.0-fix-product_print_category_product_template_related_fields branch from d5d7e05 to 61ae3f8 Compare October 28, 2024 07:42
…dant field

This should have been obvious from the start...

Signed-off-by: Carmen Bianca BAKKER <[email protected]>
@carmenbianca
Copy link
Contributor

@huguesdk i fixed this a final time with a solution that is way more obvious. the tests succeed on my machine.

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.

3 participants