-
-
Notifications
You must be signed in to change notification settings - Fork 703
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
[ADD] product_pricelist_margin #1561
base: 16.0
Are you sure you want to change the base?
[ADD] product_pricelist_margin #1561
Conversation
d577643
to
9e28a94
Compare
) | ||
|
||
@api.depends("fixed_price", "cost") | ||
def _compute_margin(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.
Can you please add a unit test the behavior of this method with using pricelist item with a different price computation ?
For example : percentage or formula
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.
Interesting module. However, if you want to compute margin you should depends on account to take into account the vat that can be included.
See similar module : https://github.com/OCA/product-attribute/blob/16.0/product_pricelist_simulation_margin/wizards/wizard_preview_pricelist.py#L42
9e28a94
to
03916fe
Compare
with Form(self.line) as line: | ||
line.compute_price = "percentage" | ||
self.assertEqual(line.cost, 20.0) | ||
self.assertEqual(line.margin, 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.
We apply 20% discount and the margin is 0 ? 🤔
Hii @legalsylvain is it good for you ? have a great day |
No. Margin is still bad computed. See previous comment. |
0905b26
to
a238034
Compare
Hi @legalsylvain , Mr. @chaule97 just improved the compute function. Please have a look. Thanks. |
Hi @legalsylvain , I have updated as per your request. Hope it is good for you |
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.
"website": "https://github.com/OCA/product-attribute", | ||
"author": "Camptocamp, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"depends": ["product"], |
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.
"depends": ["product"], | |
"depends": ["account"], |
account_tax.compute_all()
function is in account module
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 one is still pending.
<field name="margin" /> | ||
<field name="margin_percent" /> |
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.
<field name="margin" /> | |
<field name="margin_percent" /> | |
<field name="margin" optional="show"/> | |
<field name="margin_percent" optional="show"/> |
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.
allow users to hide percent and / or net value if they don't need the information.
<field name="margin" /> | ||
<field name="margin_percent" /> |
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.
<field name="margin" /> | |
<field name="margin_percent" /> | |
<field name="margin" optional="show" /> | |
<field name="margin_percent" optional="show" /> |
<field name="margin" /> | ||
<field name="margin_percent" /> |
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.
<field name="margin" /> | |
<field name="margin_percent" /> | |
<field name="margin" optional="show" /> | |
<field name="margin_percent" optional="show" /> |
<field name="margin" /> | ||
<field name="margin_percent" /> |
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.
<field name="margin" /> | |
<field name="margin_percent" /> | |
<field name="margin" optional="show"/> | |
<field name="margin_percent" optional="show"/> |
<field name="model">product.pricelist.item</field> | ||
<field name="arch" type="xml"> | ||
<field name="fixed_price" position="after"> | ||
<field name="cost" /> |
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.
<field name="cost" /> | |
<field name="cost" invisible="1" /> |
/> | ||
<field name="arch" type="xml"> | ||
<field name="fixed_price" position="after"> | ||
<field name="cost" /> |
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.
<field name="cost" /> | |
<field name="cost" invisible="1" /> |
for item in self: | ||
margin = percentage = 0 | ||
if not float_is_zero( | ||
item.fixed_price, precision_digits=item.currency_id.rounding |
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.
Do not use fixed_price. better user the computation of the price done by "product.pricelist". so the value is correct for all computation type.
compute="_compute_margin", | ||
) | ||
|
||
@api.depends("fixed_price", "product_tmpl_id", "cost") |
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.
It depends on a lot of field in fact : compute_price, applied_on, percent_price, "base", "price_discount", price_surcharge, price_round, price_min_margin.
a238034
to
87b6e36
Compare
Hi @legalsylvain , I have updated. I hope it was fine |
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.
Thanks ! some remaining points inline.
the rests looks great to me !
"website": "https://github.com/OCA/product-attribute", | ||
"author": "Camptocamp, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"depends": ["product"], |
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 one is still pending.
): | ||
margin = percentage = 0 | ||
|
||
price_rule = item.pricelist_id._compute_price_rule(item.product_tmpl_id, 1) |
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 guess that 1 is the quantity. If yes, it should be replaced by the min quantity of the item. don't you think ?
def _compute_margin(self): | ||
for item in self.filtered( | ||
lambda x: x.applied_on in ("1_product", "0_product_variant") | ||
and x.compute_price == "fixed" |
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.
and x.compute_price == "fixed" |
I don't understand this line. The algorithm can work for all compute_price method. don't you think ?
|
||
for item in self.filtered( | ||
lambda x: x.applied_on not in ("1_product", "0_product_variant") | ||
or x.compute_price != "fixed" |
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.
or x.compute_price != "fixed" |
same here.
8b93a6b
to
aa06320
Compare
Hi @legalsylvain , I have updated it. please review again |
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.
not an expert but LGTM
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.
Minor comment (optional). Otherwise LG
aa06320
to
f2b6cdb
Compare
# Copyright 2024 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Product Pricelist Margins", |
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.
module name should not end w/ plural form. Please rename it to _margin
.
See pt 1 https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#11modules
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 @simahawk, I have updated it. Thanks for your suggestion
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestMargin(TransactionCase): |
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.
pls usa BaseCommon as base class to disable tracking
"price_min_margin", | ||
"product_tmpl_id", | ||
"cost", | ||
"min_quantity", |
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.
"min_quantity", | |
"min_quantity", | |
"fixed_price", |
<field name="inherit_id" ref="product.product_pricelist_item_tree_view" /> | ||
<field name="arch" type="xml"> | ||
<field name="price" position="after"> | ||
<field name="cost" /> |
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.
<field name="cost" /> | |
<field name="cost" invisible="1"/> |
<field name="margin" optional="show" /> | ||
<field name="margin_percent" optional="show" /> |
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.
<field name="margin" optional="show" /> | |
<field name="margin_percent" optional="show" /> | |
<field name="margin" optional="show" attrs="{'invisible': [('applied_on', 'not in', ["1_product", "0_product_variant"])]}" /> | |
<field name="margin_percent" optional="show" attrs="{'invisible': [('applied_on', 'not in', ["1_product", "0_product_variant"])]}" /> |
<field name="margin" optional="show" /> | ||
<field name="margin_percent" optional="show" /> |
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.
<field name="margin" optional="show" /> | |
<field name="margin_percent" optional="show" /> | |
<field name="margin" optional="show" attrs="{'invisible': [('applied_on', 'not in', ["1_product", "0_product_variant"])]}"/> | |
<field name="margin_percent" optional="show" attrs="{'invisible': [('applied_on', 'not in', ["1_product", "0_product_variant"])]}"/> |
<field name="model">product.pricelist.item</field> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//group[@name='pricelist_rule_base']/div" position="after"> | ||
<group attrs="{'invisible': [('compute_price', '!=', 'fixed')]}"> |
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.
<group attrs="{'invisible': [('compute_price', '!=', 'fixed')]}"> | |
<group attrs="{'invisible': [('applied_on', 'not in', ["1_product", "0_product_variant"])]}"> |
f2b6cdb
to
8fc7577
Compare
Hi @legalsylvain , I have updated it. please review again |
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.
Thanks for your contribution !
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.
A little bit of cleanup is still required 😉
Please:
- find n replace
product_pricelist_margins
everywhere (eg: translations) - rewrite the commit message as well
8fc7577
to
96e33be
Compare
Thanks @simahawk . I have replaced all of them |
item.margin_percent = 0 | ||
continue | ||
|
||
res = item.product_tmpl_id.taxes_id.compute_all( |
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.
res = item.product_tmpl_id.taxes_id.compute_all( | |
current_company = self.env.company | |
res = item.product_tmpl_id.taxes_id.filtered(lambda t: t.company_id and t.company_id == current_company).compute_all( | |
price, | |
item.currency_id, | |
product=item.product_tmpl_id, | |
) |
taxe_id
is a M2M. In multicompany mode all taxes linked to this product (doesn't matter the company) will be taken into account to compute total_excluded
. That is not correct from the point of view of the user. IMO we should take into account only the products taxes belonging to the current logged company.
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 have updated it
96e33be
to
612e178
Compare
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.
quick review. no test.
LGTM. Thanks for applying change requests !
612e178
to
2dc3934
Compare
This module shows the product's cost and margin from the pricelists.