-
-
Notifications
You must be signed in to change notification settings - Fork 766
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] Port purchase_discount #316
Conversation
Please import latest commits from 9.0 using https://github.com/OCA/maintainer-tools/wiki/Migration-to-version-10.0 and check Travis status |
And, hey, congratulations for your successfully deployment of v10 on January! |
@pedrobaeza I checked that the code didn't change between 9.0 and 10.0, but I forgot to check translations. It's done now. |
Please check PEP8:
And I would thank if you squash all the "OCA Transbot" commits in one. |
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.
Hi Alexis,
Thanks for porting this usefull module. Some remarks inline. LGTM otherwise. good news to have fixed the report issue.
@@ -1,21 +1,14 @@ | |||
# -*- coding: utf-8 -*- |
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.
git mv purchase_discount/models/account_invoice_line.py purchase_discount/models/account_invoice.py
<record model="ir.ui.view" id="purchase_discount_order_line_form2"> | ||
<field name="name">purchase_discount.order.line.form2 (purchase_discount)</field> | ||
<record model="ir.ui.view" id="purchase_order_line_form2"> | ||
<field name="name">purchase_discount.order.line.form2</field> |
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.
name field is unnecessary for views. (it is autogenerated).
Thank you for the port. Nothing to add from the comments up. 👍 |
You will find a small path for the pep8 PR on your branch |
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.
Tested and code reviewed. Thanks!
Please squash all "OCA Transbot" commits together |
This is still red on Travis + need commit squashing for "OCA Transbot". Can you please do it? |
Fixing lint with akretion#3 |
600c03d
to
bf8d86e
Compare
@pedrobaeza I merged @eLBati PEP 8 PR and squashed the "OCA Transbot" commits together. |
I forgot to mention it here sorry, but there is a bug in the current version of the module which gives random results on the amount without tax of the purchase order line. And the fix I made on June 23 fixes some bugs, but not all. I think it's due to the code of _compute_amount on purchase.order.line https://github.com/akretion/purchase-workflow/blob/10-port-purchase_discount/purchase_discount/models/purchase_order.py#L50 which writes price_unit before calling super() and re-write it after. I'm pretty sure it causes some race condition problems. The other problem is the fact that this module changes the meaning of the "price_unit" field from net price to gross price. I have 1 small company using this module in production and they are very angry about it. I think I'll completely re-write this module with a different approach where the meaning of the price_unit field is not changed and where we don't use the "trick" to re-write price_unit before and after calling super(). |
Hi, @alexis-via. I'm creating a new module that extends this PR to have three successive discounts (#432). I didn't come across tax problems on my tests. Can you give me a tip on how to replicate that kind of issues? |
You could try calling _compute_amount's super() one by one, passing actual unit price * quantity as base amount in the context https://github.com/odoo/odoo/blob/10.0/addons/account/models/account.py#L767. You probably need to assign the resulting record updates back to the original records from before the context change. |
|
||
|
||
class PurchaseOrderLine(models.Model): | ||
_inherit = "purchase.order.line" | ||
|
||
@api.depends('discount') | ||
@api.depends('product_qty', 'price_unit', 'taxes_id', 'discount') | ||
def _compute_amount(self): | ||
prices = {} |
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.
@alexis-via I agree with @StefanRijnhart . When you call self super, some cache issues were happening that are solved calling from inside the recordset loop. Indeed, you could put this into a method and use it to extend the other ones instead of overriding them. Take a look at my PR if you want to (#432) 🙂
@api.depends('product_qty', 'price_unit', 'taxes_id', 'discount')
def _compute_amount(self):
for line in self:
# super() update resets fields from cache in some circumstances.
# It's convenient to have this assignation by default so other
# modules can extend this method without issues.
price = line.price_unit
if line.discount:
line.price_unit *= (1 - line.discount / 100.0)
super(PurchaseOrderLine, line)._compute_amount()
if line.discount:
line.price_unit = price
@api.multi | ||
def _get_stock_move_price_unit(self): | ||
# method copy-pasted from odoo/addons/purchase/models/purchase.py | ||
self.ensure_one() |
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.
This is breaking inheritance also. This is worse than the previous method.
@api.depends('order_line.price_total') | ||
def _amount_all(self): | ||
# Method copy-pasted from odoo/addons/purchase © Odoo S.A. | ||
for order in self: |
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.
This can't be changed without calling super. You are breaking inheritance here.
@api.model_cr | ||
def init(self): | ||
tools.drop_view_if_exists(self._cr, 'purchase_report') | ||
self._cr.execute(""" |
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.
This is also breaking inheritance. Do something similar to what I have done in https://github.com/OCA/purchase-reporting/blob/9.0/purchase_reporting_weight/reports/purchase_report.py
OCA Transbot updated translations from Transifex OCA Transbot updated translations from Transifex OCA Transbot updated translations from Transifex OCA Transbot updated translations from Transifex
0f22a23
to
4b5f561
Compare
I have improved the PR respecting inheratibility and adding tests for the untested parts (move price unit and purchase report). |
vals = {} | ||
for line in order.order_line.filtered('discount'): | ||
vals[line] = line.price_unit | ||
line.price_unit *= (1 - line.discount) / 100.0 |
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.
@pedrobaeza If you'd took this calculation into a separte method it'd make extensibility way more simple. Something of the like:
def _compute_discount(self, price):
return price * (1 - self.discount or 0.0 / 100.0)
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.
OK, I'll do that.
4b5f561
to
e2416e6
Compare
@chienandalu I have changed the PR for having inheritable methods. Now you only need to overwrite |
e2416e6
to
aceb2eb
Compare
Fixes #265
Note that I still discourage users from adopting purchase_discount, because it changes the meaning of the price_unit field, which makes the module incompatible with all the modules that use the field price_unit in it's original meaning.
But I tried the known issues of the module on purchase reports and stock valuation.