Skip to content

[16.0[IMP]account_commission: add payment date limit on settle commissions#588

Merged
OCA-git-bot merged 1 commit intoOCA:16.0from
odooNextev:16.0-imp-account_commission
Jun 27, 2025
Merged

[16.0[IMP]account_commission: add payment date limit on settle commissions#588
OCA-git-bot merged 1 commit intoOCA:16.0from
odooNextev:16.0-imp-account_commission

Conversation

@matteonext
Copy link
Contributor

@matteonext matteonext commented Dec 20, 2024

Porting #441

@OCA-git-bot
Copy link
Contributor

Hi @pedrobaeza,
some modules you are maintaining are being modified, check this out!

@matteonext matteonext force-pushed the 16.0-imp-account_commission branch from ba276da to 50f6a32 Compare December 20, 2024 10:21
@matteonext matteonext changed the title [IMP]account_commission: possibility to add payment date limit on set… [16.0[IMP]account_commission: add payment date limit on settle commissions Dec 20, 2024
Copy link

@PicchiSeba PicchiSeba left a comment

Choose a reason for hiding this comment

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

Code review

"""
self.ensure_one()
payment_based_commission = (
True if self.commission_id.invoice_state == "paid" else False

Choose a reason for hiding this comment

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

nitpick: this expression could be simplified

Suggested change
True if self.commission_id.invoice_state == "paid" else False
self.commission_id.invoice_state == "paid"

@matteonext matteonext force-pushed the 16.0-imp-account_commission branch from 50f6a32 to 8a9338b Compare December 20, 2024 10:56
Copy link

@odooNextev odooNextev left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +57 to +59
context_date_payment = self.env.context.copy()
context_date_payment["date_payment_to"] = self.date_payment_to
self.env.context = context_date_payment
Copy link

@PicchiSeba PicchiSeba Feb 28, 2025

Choose a reason for hiding this comment

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

question: aren't these operations equivalent to

self.env.context["date_payment_to"] = self.date_payment_to

?

Or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @PicchiSeba, self.env.context is a frozendict, which is an immutable dictionary. Because of this, I couldn't add self.date_payment_to directly as you suggested.

Copy link
Member

Choose a reason for hiding this comment

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

Please use with_context decorator instead of a hard replacement of this type, as it's not guaranteed that the internal implementation will work with this kind of operations.

Copy link

@PicchiSeba PicchiSeba left a comment

Choose a reason for hiding this comment

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

Code review: LGTM

@matteonext
Copy link
Contributor Author

@pedrobaeza What do you think? is it possible to merge?

@pedrobaeza pedrobaeza added this to the 16.0 milestone Mar 3, 2025
Comment on lines +57 to +59
context_date_payment = self.env.context.copy()
context_date_payment["date_payment_to"] = self.date_payment_to
self.env.context = context_date_payment
Copy link
Member

Choose a reason for hiding this comment

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

Please use with_context decorator instead of a hard replacement of this type, as it's not guaranteed that the internal implementation will work with this kind of operations.

@matteonext matteonext force-pushed the 16.0-imp-account_commission branch from 4ad98ba to d5c0a62 Compare March 3, 2025 08:28
@PicchiSeba
Copy link

Please use with_context decorator instead of a hard replacement of this type, as it's not guaranteed that the internal implementation will work with this kind of operations.

@pedrobaeza

Shouldn't we prefer this approach instead of with_context? The old context would be discarded entirely

@pedrobaeza
Copy link
Member

No, with_context can have an entire dict as argument or just a context key. Depending on which you select, you will have a replacement or just a new/edited key.

@matteonext matteonext requested a review from pedrobaeza March 27, 2025 10:44

def action_settle(self):
self = self.with_context(date_payment_to=self.date_payment_to)
return super().action_settle()
Copy link

@TheMule71 TheMule71 Apr 10, 2025

Choose a reason for hiding this comment

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

Is this covered by a test?
My doubt is that self gets reassigned locally. I'm not sure that super() w/o arguments uses local self. So I'm not sure it works.

I'd suggest the explicit syntax:

return super(CommissionMakeSettle, self).action_settle()

to make sure that it's the modified self that gets used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @TheMule71, thanks for your review. I've just added a coverage test and it seems to work properly as it is now. Do you think it's better to make the syntax more explicit, as you mentioned? Thanks!

Choose a reason for hiding this comment

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

No, it's not necessary.

@matteonext matteonext force-pushed the 16.0-imp-account_commission branch from d5c0a62 to 3a9c534 Compare April 10, 2025 09:22
@matteonext
Copy link
Contributor Author

@pedrobaeza merge?

@pedrobaeza
Copy link
Member

This is adding a bit of complication on the module for a specific case, but it's not too much overhead and it's tested, so let's continue.

/ocabot merge minor

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-588-by-pedrobaeza-bump-minor, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 6d215fa into OCA:16.0 Jun 27, 2025
6 of 7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at de7708e. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants