-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[14.0][ADD]sale_order_general_discount_payment_term: Add sale order general discount on payment term #2660
[14.0][ADD]sale_order_general_discount_payment_term: Add sale order general discount on payment term #2660
Conversation
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.
Functional ok!
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.
You hide the original field, but for existing installations the value of sale_discount
on res.partner
s will still exist and it will keep being applied to sale.order
s, with no way for the user to change it.
There are a few options to deactivate it entirely, One of them could be a post_init_hook
that just writes 0
on every partner's sale_discount
field. I don't know if people would find it too aggressive, though.
Another option is to override onchange_partner_id
, save the existing discount, call super()
and then restore the discount that existed before the onchange
was called, so as to nullify the effect of the change in sale_order_general_discount
(every line's discount would be recalculated twice for nothing, but alas, I've seen worse in Odoo :D ).
Alternatively, since sale_order_general_discount
is so small and you want to deactivate half of it, you could just replicate its functionality and not depend on it. (and maybe add it to the excludes
key in the manifest so people don't accidentally install both).
I think option number 2 (overriding onchange_partner_id
is by far the most preferable, though)
sale_discount = fields.Float( | ||
store=True, | ||
readonly=False, | ||
) |
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.
No point restating obvious defaults IMO. (This is a new field, not an override, correct?)
Instead, I think it'd be good to add the same modifiers that the corresponding field has in sale_order_general_discount
sale_discount = fields.Float(
digits=dp.get_precision('Discount'),
string='Discount (%)',
company_dependent=True,
track_visibility="onchange",
)
<xpath | ||
expr="//page[@name='sales_purchases']//label[@for='sale_discount']" | ||
position="attributes" | ||
> | ||
<attribute name="invisible">1</attribute> | ||
</xpath> | ||
<xpath | ||
expr="//page[@name='sales_purchases']//div[field[@name='sale_discount']]" | ||
position="attributes" | ||
> | ||
<attribute name="invisible">1</attribute> | ||
</xpath> |
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.
<xpath | |
expr="//page[@name='sales_purchases']//label[@for='sale_discount']" | |
position="attributes" | |
> | |
<attribute name="invisible">1</attribute> | |
</xpath> | |
<xpath | |
expr="//page[@name='sales_purchases']//div[field[@name='sale_discount']]" | |
position="attributes" | |
> | |
<attribute name="invisible">1</attribute> | |
</xpath> | |
<field name="sale_discount" position="attributes"> | |
<attribute name="invisible">1</attribute> | |
</field> |
is this not sufficient, or does it not work for some reason?
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 @aleuffre, thanks for your review. Set "invisible" on field sale_discount it doesn't works properly because we need to hide a div with sale_discount and a string inside.
@api.depends("payment_term_id") | ||
def _compute_general_discount(self): | ||
for so in self: | ||
so.general_discount = so.payment_term_id.sale_discount |
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.
api.depends
and _compute
functions are generally used if they're computing the value of a field.
I think this should be an api.onchange
Cf. the module sale_order_general_discount
:
@api.onchange('partner_id')
def onchange_partner_id(self):
super().onchange_partner_id()
self.general_discount = self.partner_id.sale_discount
return
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 @aleuffre, I think that is 12.0 version. In v14 this is the code in sale_order_general_discount:
@api.depends("partner_id")
def _compute_general_discount(self):
for so in self:
so.general_discount = so.partner_id.sale_discount
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.
Ah, my bad. If you're overriding an existing compute and it works, then that's fine by me.
Sorry for my oversights during my first review. Trying to do too many things at once will do that to you. Adding the field parameters to |
e2a82b1
to
3a64185
Compare
digits="Discount", | ||
string="Discount (%)", | ||
company_dependent=True, | ||
track_visibility="onchange", |
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.
as you correctly spotted in the other comment, I was looking at v12 code during my previous review.
track_visibility
was a v12 option, in v14 it's simply tracking=True
Code review looks good aside from that one small thing, please squash everything into a single commit. |
e466597
to
1a04352
Compare
@OCA/crm-sales-marketing-maintainers good for merge? |
@pedrobaeza could this be merged please? |
expr="//page[@name='sales_purchases']//label[@for='sale_discount']" | ||
position="attributes" | ||
> | ||
<attribute name="invisible">1</attribute> |
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 not correct. This is out of scope of the module. And there's already a group for hiding this for those you don't want to see it.
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 the point of this change is that if there is a general discount set in partner and another general discount set in payment term they will be in conflict for setting the general discount on SO.
How else do you suggest we avoid this scenario?
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, then hide it only if the payment term is set and it contains a discount.
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.
Sorry, the flow is unclear to me. What happens if partner 1 has a default general discount set and in SO user selects a payment term with a general discount? Which general discount should be applied?
With this module installed, it's very likely that the only general discount that should be applied is the payment term one.
Shall we make it easier with a flag in settings allowing user to decide whether to hide the general discount in partner 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.
You should clear that general discount on payment term assignment IMO.
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.
The question is that you shouldn't remove the possibility of assigning directly a general discount for all cases. Just for those covered by this module (with payment term). If not, you will force to assign a payment term always if you want a general discount.
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.
User has the possibility of assigning general discount in SO in 3 ways:
- default from partner
- manually from field "discount" in SO
- default from payment term
base module "sale_order_general_discount" implements the first two options; this module implements the third.
I think if we add a "hide default general discount in partner" flag in settings to this module we will have the cleaner implementation as the user can decide:
- whether to keep all 3 options,
- to keep only 2 and 3 (flag enabled), or
- to keep 1 and 2 by not installing this module.
Could that work?
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 still think that you don't need another extra config. Just don't hide the field if you don't have a payment term selected.
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.
Alright, @odooNextev can you implement that?
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 with the latest change by @odooNextev , if payment term discount = 0 and partner default discount is set, partner default is used in SO; otherwise payment term discount is used. Could this work?
e6c0a55
to
f04fe42
Compare
f04fe42
to
c43a9cc
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.
/ocabot merge nobump
Hey, thanks for contributing! Proceeding to merge this for you. |
This PR has the |
1 similar comment
This PR has the |
Congratulations, your PR was merged at fca3a24. Thanks a lot for contributing to OCA. ❤️ |
This modulo allow to add sale_order general discount based on payment term discount field.
Also hide discount from partner to avoid conflicts