-
-
Notifications
You must be signed in to change notification settings - Fork 526
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
[16.0][IMP] account_payment_partner: add hook to get recipient bank #1300
base: 16.0
Are you sure you want to change the base?
[16.0][IMP] account_payment_partner: add hook to get recipient bank #1300
Conversation
Please give more details about the change... As is, it doesn't seem a correct or desirable change |
d28a0bf
to
b118fa3
Compare
b118fa3
to
024d4be
Compare
If you need to change the behavior, you shouldn't do a hook, but override the compute method, filter the records you want to modify the behavior and assign the value, and call super with the rest of the records. |
Hi @pedrobaeza, we already thought about doing what you suggest, but the problem is that this module leaves empty the partner bank in different conditions depending on whether we have a payment mode, whether it is an invoice or a bill, etc. If we override the compute method, we need to replicate again all these evaluations on the new specific module. By using the hook, we can simply check if the logic on this module is leaving the result empty or not, and then apply our desired custom behavior. Moreover, calling the super() method with only a subset of the records, as you also suggest, can be problematic, because if there are other modules applying a different logic to assign the partner bank, we need to be able to call the super() method with all of the records. What do you think? |
I understand that it seems more complicated, and it's in some cases, but at the end, it's the winning strategy, as you don't always have the option to add these hooks, and you develop a strategy for how to deal with any computed field. Anyway, even having the option, this complicates the code, making it less readable. For both cases you have said, the solution is to call And about the performance, of course these strategies causes a bit of overhead, but they are barely appreciable in the general computation. |
Our main issue revolves around the compute method resetting the field to False, which overrides the value set by the super() method. If you have a specific case where you want to use this module's logic in case there is a payment mode, as well as the base module's logic when there is no payment mode, you cannot do it anymore, since the value computed in the base module will have been overridden by this method (and set to False in case there is no payment mode). Still, we will try to implement it by overriding the compute method, as you suggested. |
For such case, you can do: def _compute_partner_bank_id(self):
prev_data = {x: x.partner_bank_id for x in self}
res = super()._compute_partner_bank_id()
for record in prev_data:
if not record.partner_bank_id and prev_data[record]:
record.partner_bank_id = prev_data[record]
return res |
This won't work for us, since we want to use the standard logic for setting the partner_bank_id in case there we do not have payment mode. With the method you suggested, after the field is set in the base module, it gets overwritten by the method in the account_payment_partner module, and set to False, so we have no way of knowing what value was computed originally (in the base module). That's why we thought of using the hook, to make sure that the value set by the standard logic of this method was not overwritten and set to False by the account_payment_partner module. I hope this explanation clarifies the issue. :) |
OK, got it, but I think in this case the best is that you overwrite the compute method and re-add the same logic as in core in your custom. Although copy/paste is not the recommended technique for most of the things, in this case, you are assuring that you get the desired behavior no matter if there are upstream changes here on in Odoo core, and being very few lines of code, it's not a big burden. |
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
This improvement adds a hook to be able to inherit easily the logic in which the partner bank is assigned. In this module, if there is no payment mode, the partner bank is set to False, but that may not be desirable in all cases.