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][FIX][sale_financial_risk] compute of risk_sale_order write on commercial partner #417

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from

Conversation

Kev-Roche
Copy link

@Kev-Roche Kev-Roche commented Jan 9, 2025

Compute of risk_sale_order write on commercial_partner_id, not on self.
cc @sebastienbeau , @alexis-via

@@ -26,7 +26,7 @@ def _get_risk_sale_order_domain(self):
risk_states = self.env["sale.order"]._get_risk_states()
return self._get_risk_company_domain() + [
("state", "in", risk_states),
("risk_partner_id", "in", self.mapped("commercial_partner_id").ids),
("risk_partner_id", "in", self.ids),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain the problem this PR is trying to solve and the steps to reproduce it?
Thanks

Copy link
Member

Choose a reason for hiding this comment

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

It's a tricky issue.

Let's explain

You open a contact "A" that have for commercial_partner_id the partner "B"
And you have an invoice of 1000€ on partner B.

You expect to have 1000€ of risk_sale_order on partner B and 0 on partner A.
If you try the module it have exactly this expected behavior.

But if you inspect the code you will see that odoo do a write when this field is computed (normally compute never call write method, and this raise issue with other module)

So let's going deeper !

When you open the form view of partner "A" the field "risk_sale_order" is computed.
So in the compute method in self you have "record A".

** Note: **
When you do a compute only record in "self" should have value assigned for two reason

  • first is useless (odoo when to compute record A, it's not needed to compute record B)
  • secondly it's broken as setting other value on a record in a compute will use a write instead of using the normal behaviour of computed field

So what happen here:

The domain is going to return the grouped amount of "sale.order.line" with the partner B (the commercial_partner_id)

Then the following code

for group in orders_group:
partner = self.browse(group["risk_partner_id"][0])
company = self.env["res.company"].browse(
group["company_id"][0] or self.env.company.id
)
company_currency = company.currency_id
partner.risk_sale_order = company_currency._convert(
group["risk_amount"],
partner.risk_currency_id,
company,
fields.Date.context_today(self),
round=False,

Is going to set the "risk_sale_order" on partner B and 0 on partner A. But as we have in self only "record A" a write will be call on "partner B". Computing the value on partner B is useless as "partner A" will always have 0 as value and this break in our case security rule as some use do not have write access on "partner B" (and so the write raise an error)

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.

3 participants