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

10.0 product supplierinfo discount #407

Merged

Conversation

StefanRijnhart
Copy link
Member

@StefanRijnhart StefanRijnhart commented Jun 5, 2017

Apart from migrating this module to 10.0, this PR suggests to handle an issue that already existed in 9.0 in 61a32a0726: because Odoo automatically creates supplierinfo entries when a purchase order is confirmed, the purchase order lines' discounts should be added to these entries.

@StefanRijnhart StefanRijnhart added this to the 10.0 milestone Jun 5, 2017
@pedrobaeza pedrobaeza mentioned this pull request Jun 5, 2017
38 tasks
@JonathanNEMRY
Copy link

@StefanRijnhart can you rebase it? The depends is now merged so I think travis should be happy with that! 😄

Copy link
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

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

Code review. (only : 9c219cf)
no test.

@StefanRijnhart StefanRijnhart force-pushed the 10.0-product_supplierinfo_discount branch from 9c219cf to 4b6bfad Compare October 31, 2017 18:46
@StefanRijnhart
Copy link
Member Author

@JonathanNEMRY thanks for noting! Now rebased.

@legalsylvain
Copy link
Contributor

legalsylvain commented Nov 1, 2017

Hi. I'm just thought about a potential improvment.

For the time being :

  • without this module, in product.supplierinfo, the 'price' field is the purchase price, (so the "Net price").
  • with this module, this field become the gross price, and we add a field 'discount'. So we change the meaning of this field.

The Idea :

With this module, the price_unit field of purchase order line stores the gross price instead of the net price, which is a change in the meaning of this field. So this module breaks all the other modules that use the price_unit field with it's native meaning.

Pro :

  • keep the meaning of the original field.
  • having both informations for the end users. (gross / net prices).
  • Futur possibility to handle rounding problem more easily. round(gross_price * (1-discount/100)) * qty != round(gross_price * qty) * (1-discount/100)

Cons :

  • More work for this PR.
  • migration script required to managed correctly transition between 10.0 (or -) and 11.0 (or +)

regards.
(really not a blocking point regarding this PR)

@StefanRijnhart
Copy link
Member Author

@legalsylvain I don't think I agree with your conclusion that this module changes the semantics of the field. Is it not the case that without this module, the price field represents both the gross price as well as the net price? You may as well add a new field for the net price instead of adding a new field for the gross price. But IMHO it is out of scope for this migration.

@legalsylvain
Copy link
Contributor

Hi @StefanRijnhart.

I don't think I agree with your conclusion that this module changes the semantics of the field

Well, for the supplierinfo, it is a matter of PoV. I can understand your. About purchase.order.line, well it is written in the current readme file, that module breaks the meaning of the price_unit field. Maybe it's wrong, but in that case, it should be removed. Don't you think ?

But IMHO it is out of scope for this migration.

Of course, as said, not a blocking point, just a question !

@rousseldenis
Copy link
Sponsor Contributor

@legalsylvain The question had to be asked. I think these concepts have to be clear for user, at least.

@pedrobaeza
Copy link
Member

The problem is that the same field, price_unit, is used for both gross value and net value in purchase core module, so it uses it for some operations as gross value and another as net value. Adding the discount, we have to interfere in all the operations where the giving meaning is the net one for adding the discount in that logic. The perfect solution would be to have both values unfolded in core (for v12 obviously), and we change the way the net value is computed in purchase_discount, purchase_triple_discount, etc.

Any way, purchase_discount handles already the only case that is related in core with net price, which is the purchase value put in the stock move for average cost price computation.

@lukebranch
Copy link

@StefanRijnhart ,

I'm going to work on an 11.0 port of this shortly (fundamentally just removing procurement.order). I just wanted to check, are there any changes planned on this PR before it's merged into 10.0 that I should take into consideration?

@StefanRijnhart
Copy link
Member Author

@lukebranch no, I think this is working fine as it is now. Maybe if you review we can have it merged!

@lukebranch
Copy link

@StefanRijnhart ,

Brilliant, thanks for the reply. I'll take a look at this over the weekend and get back to you.

@legalsylvain
Copy link
Contributor

legalsylvain commented Mar 2, 2018

@lukebranch did you take the time to review this PR ?
regards.

@apesquero
Copy link

I don't now why close the other PR if this PR is down!

@StefanRijnhart
Copy link
Member Author

Hi @apesquero what is down about this PR?

@apesquero
Copy link

Nothing, I think this PR is perfect, but it does not finish being published.

@pedrobaeza
Copy link
Member

Then make your review here and follow the process, or use it.

@StefanRijnhart
Copy link
Member Author

@pedrobaeza as the original author, can I have your additional approval on the added change in 61a32a0726?

@StefanRijnhart
Copy link
Member Author

@apesquero still looking forward to your review! Reviews are the only thing that can get any PR merged.

Copy link
Sponsor Contributor

@rousseldenis rousseldenis left a comment

Choose a reason for hiding this comment

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

Minor comments.
One can have performance impacts. Keep eye on it

product_supplierinfo = self.product_id._select_seller(
partner_id=self.partner_id, quantity=self.product_qty,
date=self.order_id.date_order and
self.order_id.date_order[:10],
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

You cannot do that. Use

fields.Date.to_string(fields.Date.from_string(self.order_id.date_order))

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed!

discount_map = dict(
[(line.product_id.product_tmpl_id.id, line.discount)
for line in self.order_line.filtered('discount')])
return super(PurchaseOrder, self.with_context(
Copy link
Sponsor Contributor

@rousseldenis rousseldenis Mar 15, 2018

Choose a reason for hiding this comment

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

As with_context() recreate new environment, it is strongly encouraged to avoid this to pass parameters. Performance reasons

But this works. Improvement in another version.

Copy link
Member Author

Choose a reason for hiding this comment

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

@rousseldenis sure, this will lead to a new read() on the purchase order and its lines but I'm a bit surprised you mention it as a bad practice. Have you got a link to guidelines from Odoo or the OCA that mention with_context as such?

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Nope, that is based on experienced cases.

For this, I don't have an immediate solution, I didn't study it deeply.

@apesquero
Copy link

@StefanRijnhart,

I'm sorry, I'm new, it's possible that I did not express myself well, I think your code is correct. I have no review!

@StefanRijnhart
Copy link
Member Author

@apesquero in that case, please go to the Review Changes on the Files Changed tab on this PR and select 'Approve'. Thanks!

@StefanRijnhart StefanRijnhart force-pushed the 10.0-product_supplierinfo_discount branch from 61a32a0 to 9f07868 Compare March 15, 2018 10:13
"""
res = super(PurchaseOrderLine, self)._onchange_quantity()
if self.product_id:
date = False
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

@StefanRijnhart Nearly, you have to define it to None. Either function _select_seller will crash (Look at it - same case here OCA/stock-logistics-warehouse#351).

Copy link
Member Author

@StefanRijnhart StefanRijnhart Mar 15, 2018

Choose a reason for hiding this comment

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

Thanks for spotting this! Changed to None and I fixed another instance of date_order[10] in this code.

@StefanRijnhart StefanRijnhart force-pushed the 10.0-product_supplierinfo_discount branch from 9f07868 to a95f1bb Compare March 15, 2018 10:22
@legalsylvain legalsylvain merged commit 474e07e into OCA:10.0 Mar 15, 2018
@StefanRijnhart
Copy link
Member Author

Thanks for your reviews everyone!

@pedrobaeza
Copy link
Member

I'm late to the party, but yes, very good addition in 61a32a0, @StefanRijnhart

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.

None yet

9 participants