-
-
Notifications
You must be signed in to change notification settings - Fork 353
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_commission_delivery_partner: Use Delivery Address Agents #593
base: 14.0
Are you sure you want to change the base?
[14.0][ADD] sale_commission_delivery_partner: Use Delivery Address Agents #593
Conversation
Hi @PicchiSeba, @renda-dev, @ilyasProgrammer, @aleuffre, |
2539fda
to
ccdfa65
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.
Functional ok!
@pedrobaeza what do you think?
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.
Partial review. See comment
@api.depends("move_id", "move_id.partner_shipping_id") | ||
def _compute_agent_ids(self): | ||
self.agent_ids = False | ||
for record in self.filtered(lambda x: x.move_id.partner_shipping_id): | ||
if not record.commission_free and record.product_id: | ||
record.agent_ids = record._prepare_agents_vals_partner( | ||
record.move_id.partner_shipping_id | ||
) |
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.
issue: overwriting functions without calling super()
is an anti-pattern and should be avoided at all costs, especially in Odoo where several different configurations of modules could be installed. In this case, _compute_agent_ids
is redefined by multiple modules, and I'm not at all sure about what the final result would be (even if the tests are currently green).
There are indeed some extreme cases where it's unavoidable, and those cases should at least be clearly signposted with comments explaining how and why this choice was made.
I think there's a fairly clean solution here that would allow us to avoid having to overwrite the function:
- in the
sale_commission
module, insale.commission.mixin
, introduce a hook function:_get_partner_for_commission
or something like that. That function would return the correct partner to use to calculate commissions. Insale.commission.mixin
that function would just raise aNotImplementedError()
. - In the
sale_commission
module, in theaccount.move.line
andsale.order.line
models, implement the "concrete" function_get_partner_for_commission
. They would returnself.move_id.partner_id
andself.order_id.partner_id
respectively. - In the
sale_commission
module, make a small change to_compute_agent_ids
so that your new function_get_partner_for_commission
is called instead of havingpartner_id
hardcoded in the function. Do this also in other modules that override_compute_agent_ids
. - In your new module, overwrite only
_get_partner_for_commission
to returnself.move_id.partner_shipping_id
andself.order_id.partner_shipping_id
. You can still do a simple override of_compute_agent_ids
to add the field you need toapi.depends
like this
@api.depends("move_id.partner_shipping_id")
def _compute_agent_ids(self):
super()._compute_agent_ids()
What do you think?
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. Thank you fo the suggestion. This approach actually improves both maintainability and flexibility of code. Let me know if everything is right
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 think the current implementation is missing point 4 and part of point 3.
@api.depends("order_id", "order_id.partner_shipping_id") | ||
def _compute_agent_ids(self): | ||
self.agent_ids = False | ||
for record in self.filtered(lambda x: x.order_id.partner_shipping_id): | ||
if not record.commission_free: | ||
record.agent_ids = record._prepare_agents_vals_partner( | ||
record.order_id.partner_shipping_id | ||
) |
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.
See other comment
c4c93ba
to
8a933ae
Compare
8a933ae
to
5ff0387
Compare
Superseeds #537