-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: 12.0
Are you sure you want to change the base?
[12.0][FIX] fix product.template related fields #173
Conversation
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."
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. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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]>
93ce600
to
589b6b4
Compare
@huguesdk added a patch to your code, internal task T12969 |
i also made a pr here : odoo/odoo#181811 |
if "active" in vals: | ||
self._compute_product_variant_id() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.value
s (PTAVs) from which thoseproduct.product
s were generated are copied. Then, during thecreate
method of the product.template, newproduct.product
s 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.product
s 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.
There was a problem hiding this comment.
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]>
d5d7e05
to
61ae3f8
Compare
…dant field This should have been obvious from the start... Signed-off-by: Carmen Bianca BAKKER <[email protected]>
@huguesdk i fixed this a final time with a solution that is way more obvious. the tests succeed on my machine. |
make
product.template.product_variant_id
a stored computed field to avoid the following error when setting theprint_category_id
orto_print
related fields: