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

[14.0][ADD] sale_commission_delivery_partner: Use Delivery Address Agents #593

Open
wants to merge 3 commits into
base: 14.0
Choose a base branch
from

Conversation

Chionne27
Copy link

Superseeds #537

@OCA-git-bot
Copy link
Contributor

Hi @PicchiSeba, @renda-dev, @ilyasProgrammer, @aleuffre,
some modules you are maintaining are being modified, check this out!

@Chionne27 Chionne27 force-pushed the 14.0-ADD-sale_commission_delivery_partner branch 2 times, most recently from 2539fda to ccdfa65 Compare January 28, 2025 12:52
@Chionne27 Chionne27 changed the title [14.0][ADD] sale commission delivery partner [14.0][ADD] sale_commission_delivery_partner: Use Delivery Address Agents Jan 29, 2025
Copy link
Contributor

@francesco-ooops francesco-ooops left a 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?

Copy link

@aleuffre aleuffre left a 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

Comment on lines 7 to 14
@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
)
Copy link

@aleuffre aleuffre Feb 5, 2025

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:

  1. in the sale_commission module, in sale.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. In sale.commission.mixin that function would just raise a NotImplementedError().
  2. In the sale_commission module, in the account.move.line and sale.order.linemodels, implement the "concrete" function _get_partner_for_commission. They would return self.move_id.partner_id and self.order_id.partner_id respectively.
  3. 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 having partner_id hardcoded in the function. Do this also in other modules that override _compute_agent_ids.
  4. In your new module, overwrite only _get_partner_for_commission to return self.move_id.partner_shipping_id and self.order_id.partner_shipping_id. You can still do a simple override of _compute_agent_ids to add the field you need to api.depends like this
    @api.depends("move_id.partner_shipping_id")
    def _compute_agent_ids(self):
        super()._compute_agent_ids()

What do you think?

Copy link
Author

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

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.

Comment on lines 7 to 14
@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
)
Copy link

Choose a reason for hiding this comment

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

See other comment

@Chionne27 Chionne27 force-pushed the 14.0-ADD-sale_commission_delivery_partner branch 3 times, most recently from c4c93ba to 8a933ae Compare February 6, 2025 15:28
@Chionne27 Chionne27 force-pushed the 14.0-ADD-sale_commission_delivery_partner branch from 8a933ae to 5ff0387 Compare February 6, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants