[18.0][IMP] purchase_order_secondary_unit: add vendor pricelist support#2932
[18.0][IMP] purchase_order_secondary_unit: add vendor pricelist support#2932OCA-git-bot merged 2 commits intoOCA:18.0from
Conversation
ae63904 to
fc3ea0f
Compare
|
Regarding the two test cases I mentioned in my previous comment, they’re out of scope for this PR. I’m also not confident they’re worth addressing right now, and we don’t expect to use those use cases at the moment—so I’ll ignore them for now. |
fc3ea0f to
1021636
Compare
736f15b to
8e4da27
Compare
|
@yostashiro Could you please review my last two commits? I will squash commits after you review. |
| <!-- Unit price: add UoM and secondary price ('secondary' and 'both' modes) --> | ||
| <xpath expr="//span[@t-field='line.price_unit']" position="after"> | ||
| <t | ||
| t-if="line.report_show_price_uom() and line.get_secondary_uom_display_mode() != 'secondary'" |
There was a problem hiding this comment.
| t-if="line.report_show_price_uom() and line.get_secondary_uom_display_mode() != 'secondary'" | |
| t-if="line.report_show_price_uom()" |
@AungKoKoLin1997 We should not change the code here. Please update line.report_show_price_uom() instead.
| <t | ||
| t-if="line.report_show_price_uom() and line.get_secondary_uom_display_mode() != 'secondary'" | ||
| > | ||
| / <span t-field="line.product_uom.name" /> | ||
| </t> | ||
| <t t-if="line.get_secondary_uom_display_mode() == 'secondary'"> | ||
| <span t-field="line.secondary_uom_price" /> | ||
| <t t-if="line.report_show_price_uom()"> | ||
| / <span | ||
| t-field="line.secondary_uom_id.name" | ||
| groups="uom.group_uom" | ||
| /> | ||
| </t> | ||
| </t> | ||
| <t t-if="line.get_secondary_uom_display_mode() == 'both'"> | ||
| <br /> | ||
| <span class="text-muted"> | ||
| (<span t-field="line.secondary_uom_price" /> | ||
| / <span | ||
| t-field="line.secondary_uom_id.name" | ||
| groups="uom.group_uom" | ||
| />) | ||
| </span> | ||
| </t> |
There was a problem hiding this comment.
I guess we could create a common template and call it from both report and portal view.
| @@ -0,0 +1,89 @@ | |||
| <odoo> | |||
| <!-- Unit price: add UoM and secondary price ('secondary' and 'both' modes) --> | |||
| <template id="purchase_secondary_uom_price"> | |||
There was a problem hiding this comment.
| <template id="purchase_secondary_uom_price"> | |
| <template id="purchase_uom_price"> |
There was a problem hiding this comment.
I changed the template name.
|
@AungKoKoLin1997 Looks good. 👍 Please go ahead and squash commits. |
91f742d to
3a74084
Compare
|
Depends on OCA/product-attribute#2182. |
|
I added new commit to propagate |
| else: | ||
| rec.secondary_uom_price = 0.0 | ||
|
|
||
| @api.onchange("secondary_uom_price") |
There was a problem hiding this comment.
| @api.onchange("secondary_uom_price") |
I think we don't have to use @api.onchane for _inverse function.
There was a problem hiding this comment.
I removed the onchange myself and tested the behavior, and found that the value isn’t updated dynamically until the record is saved.
With onchange in place, it seems the value updates dynamically as soon as it’s written, even before saving.
So, we should have api.onchane for this _inverse function.
There was a problem hiding this comment.
Maybe you can directly update the price in _onchange_product_id_secondary_uom and skip adding the onchange in the inverse.
There was a problem hiding this comment.
We could add a new onchange method that replicates the logic of this inverse (I guess _onchange_product_id_secondary_uom is not the one to work on) if we should be strict about not using onchange with an inverse.
I see a lot of these patterns, though, in the standard codebase, so I thought it was a widely accepted practice.
There was a problem hiding this comment.
Why not reusing the onchange_product_id_secondary_uom? You update secondary_uom_id and price which is related with it in a single transaction
There was a problem hiding this comment.
We could make it work but I don't feel there is a good reason to do so as the intents are different.
There was a problem hiding this comment.
Ok, not blocking the decision, let me know when we can move it forward, appreciate that the module has been functional tested deeply :)
There was a problem hiding this comment.
Thanks! You can go ahead and merge this if you are okay with the current code, or should we add new onchange methods to remove the onchange from inverses?
| else: | ||
| rec.secondary_uom_price = 0.0 | ||
|
|
||
| @api.onchange("secondary_uom_price") |
There was a problem hiding this comment.
| @api.onchange("secondary_uom_price") |
I think we don't have to use @api.onchane for _inverse function.
There was a problem hiding this comment.
I removed the onchange myself and tested the behavior, and found that the value isn’t updated dynamically until the record is saved.
With onchange in place, it seems the value updates dynamically as soon as it’s written, even before saving.
So, we should have api.onchane for this _inverse function.
nobuQuartile
left a comment
There was a problem hiding this comment.
LGTM
Code review and functional review
f3c57f1 to
3ad0c96
Compare
|
This PR has the |
1 similar comment
|
This PR has the |
HviorForgeFlow
left a comment
There was a problem hiding this comment.
Code review, as it looks like adding a api.onchange in the inverse can work, because in the user interface the compute is not done until you save, you could add that price recalculation directly on the secondary uom on change, you can try, if this does not work we can go with your option
| else: | ||
| rec.secondary_uom_price = 0.0 | ||
|
|
||
| @api.onchange("secondary_uom_price") |
There was a problem hiding this comment.
Maybe you can directly update the price in _onchange_product_id_secondary_uom and skip adding the onchange in the inverse.
| else: | ||
| rec.secondary_uom_price = 0.0 | ||
|
|
||
| @api.onchange("secondary_uom_price") |
|
@HviorForgeFlow Thank you very much for your review. Commented here: #2932 (comment) |
HviorForgeFlow
left a comment
There was a problem hiding this comment.
Code is not beautiful as it could be but it works.
My second concern is about adding that compute store fields.
@pedrobaeza what do you think about the onchange in the inverse and the compute store? Thanks in advice for taking your time to respond
| secondary_uom_price = fields.Float( | ||
| string="Secondary Price", | ||
| digits="Product Price", | ||
| aggregator="avg", | ||
| compute="_compute_secondary_uom_price", | ||
| inverse="_inverse_secondary_uom_price", | ||
| store=True, | ||
| ) |
There was a problem hiding this comment.
My next concern is that this compute store can slowdown the update of the module for big databases.
Maybe we need a migration script where we create the column and fill it manually with a sql query.
There was a problem hiding this comment.
Yes, the Héctor's concern is legit. About being computed or use onchanges, I usually prefer computed fields for not depending on UI, but sometimes the things get messy due to dependencies, and a simple onchange resolves the usability question.
There was a problem hiding this comment.
Hi @pedrobaeza , I think Héctor is concerned about adding @api.onchange to inverse methods. Do you have any thoughts on this?
There was a problem hiding this comment.
Well, I meant about making it computed stored. About reusing inverse methods as onchange may be legit for reflecting things in UI, but it depends on the logic of inverse method.
Thanks for catching this! @AungKoKoLin1997 Can you please help add a migration script for the purchase order line field? |
3ad0c96 to
2f98124
Compare
@yostashiro Done! |
| UPDATE purchase_order_line pol | ||
| SET secondary_uom_price = | ||
| COALESCE( | ||
| pol.price_unit * ( | ||
| SELECT su.factor | ||
| FROM product_secondary_unit su | ||
| WHERE su.id = pol.secondary_uom_id | ||
| ), | ||
| 0.0 | ||
| ); |
There was a problem hiding this comment.
I suppose this would be more performant?
| UPDATE purchase_order_line pol | |
| SET secondary_uom_price = | |
| COALESCE( | |
| pol.price_unit * ( | |
| SELECT su.factor | |
| FROM product_secondary_unit su | |
| WHERE su.id = pol.secondary_uom_id | |
| ), | |
| 0.0 | |
| ); | |
| UPDATE purchase_order_line pol | |
| SET secondary_uom_price = pol.price_unit * su.factor | |
| FROM product_secondary_unit su | |
| WHERE su.id = pol.secondary_uom.id; |
There was a problem hiding this comment.
The bump should be "minor". i.e. 18.0.1.0.1 -> 18.0.1.1.0
… report config - Extend product.supplierinfo and purchase.order.line to support secondary unit pricing - Update purchase order/quotation reports to show secondary unit prices according to the configuration
… move line This commit propagates secondary_uom_id from purchase order lines to account move lines when the field exists on account.move.line. This is useful when account_move_secondary_unit is installed, and avoids the need for a glue module.
2f98124 to
9970e65
Compare
|
Looks good now. |
|
/ocabot merge minor |
|
What a great day to merge this nice PR. Let's do it! |
|
Congratulations, your PR was merged at 695e72e. Thanks a lot for contributing to OCA. ❤️ |
|
@mav-adhoc Oops, OCA/product-attribute#2182 needs to be merged, or we need to revert the parts that use hide_secondary_uom_column(). @sergio-teruel Would you be able to take a look at OCA/product-attribute#2182? |
| <xpath expr="//span[@t-field='line.product_qty']" position="attributes"> | ||
| <attribute | ||
| name="t-if" | ||
| >line.get_secondary_uom_display_mode() != 'secondary'</attribute> |
There was a problem hiding this comment.
@yostashiro Where is this function? We updated and getting errors as not existing, can't find anywhere.
There was a problem hiding this comment.
This PR depends on OCA/product-attribute#2182, and the function is introduced in that PR , as I mentioned in #2932 (comment) . Unfortunately, this PR was merged before the dependency PR was merged. @yostashiro also explained the situation in the comment above: #2932 (comment).
There was a problem hiding this comment.
OK, we have pinned to old version anyway after review as we really don't want these changes. In my opinion this should have been a seperate extension module, not because of the breakage, but it is for a feature that not everyone will want, its not really fixing an obvious oversight or error in functionality. In my experience this module is mostly used for straight conversions of qty's and adding price features just makes harder.
There was a problem hiding this comment.
@gdgellatly That's a fair point and we did consider a split. The tradeoff is four additional modules across the core apps (xxx_secondary_unit_price for product, purchase, sale, and account), and we thought the maintenance overhead would outweigh the benefit. Our clients who need the secondary unit conversion also tend to need pricing per secondary unit, and all the added features here are effectively opt-in. That said, we are happy to split the module if the PSC opts for it. You can also leave a comment on OCA/product-attribute#2182 as it gets harder to change direction after merge.
There was a problem hiding this comment.
@yostashiro Honestly it is no big deal, we have pinned now and that will get us through the v18 lifecycle which is only a few more months. For us a secondary unit is just a conversion to a primary unit, so price_subtotal is always identical and secondary_price_unit if we had would always just be price_subtotal/secondary_qty
And then look again during migration to decide what to do.
celm1990
left a comment
There was a problem hiding this comment.
I think this PR must be reverted until the dependency OCA/product-attribute#2182
is merged; otherwise, this module is broken when you try to print the report.
|
@AungKoKoLin1997 Can you please help create a PR to revert the template adjustments to avoid printing errors? @celm1990 The dependency is now OCA/product-attribute#2211 by the way. We could also have it merged quickly if it gets support from the community. |
|
Here is a follow-up: #2953 |















Add company setting to control price display in purchase reports (primary only, prioritize secondary, or both)-> Moved to product_secondary_unit@qrtl QT6202