Skip to content

[19.0][ADD] account_financial_risk_global: new module#559

Open
gdgellatly wants to merge 1 commit into
OCA:19.0from
nzroof:19.0-add-account_financial_risk_global
Open

[19.0][ADD] account_financial_risk_global: new module#559
gdgellatly wants to merge 1 commit into
OCA:19.0from
nzroof:19.0-add-account_financial_risk_global

Conversation

@gdgellatly

Copy link
Copy Markdown

Summary

  • New module account_financial_risk_global that evaluates partner financial risk across all companies
  • The credit_limit field on res.partner is global, but account_financial_risk restricts risk queries to the current user's companies, creating a gap where a partner can exceed their limit across companies without triggering an exception from any single company's view
  • This module removes the company filter (_get_risk_company_domain returns Domain.TRUE) and runs the risk computation with sudo() so that totals always reflect the partner's full exposure

Technical details

  • Overrides _get_risk_company_domain() to return Domain.TRUE (include all companies)
  • Overrides _compute_risk_account_amount() to run via sudo() so cross-company journal items are visible
  • Amounts from other companies' receivable accounts are classified under risk_account_amount / risk_account_amount_unpaid (not risk_invoice_open) since property_account_receivable_id is company-specific — but they still count toward risk_total
  • No configuration required — installing the module is sufficient

Test plan

  • 6 unit tests covering multi-company scenarios
  • test_risk_domain_is_global — domain returns Domain.TRUE
  • test_risk_totals_span_companies — draft invoices in 2 companies sum correctly
  • test_exception_triggered_globally — credit limit exceeded with combined amounts
  • test_no_exception_within_limit — no false positive within limit
  • test_posted_invoices_span_companies — posted invoices across companies count in risk total
  • test_single_company_user_still_sees_global_risk — user with single-company access sees full global risk
  • All pre-commit hooks pass (ruff, pylint_odoo, prettier)
  • Clean install + test-enable on fresh database

@OCA-git-bot OCA-git-bot added series:19.0 mod:account_financial_risk_global Module account_financial_risk_global labels Apr 26, 2026
Evaluate partner financial risk across all companies.

The credit_limit field on res.partner is global, but
account_financial_risk restricts risk queries to the current
user's companies. This creates a gap where a partner can exceed
their limit across companies without triggering an exception.

This module removes the company filter and runs the risk
computation with sudo so that totals always reflect the
partner's full exposure across every company in the database.
@gdgellatly gdgellatly force-pushed the 19.0-add-account_financial_risk_global branch from 29f8e72 to 57406a7 Compare April 26, 2026 23:33
@rvalyi rvalyi changed the title [ADD] account_financial_risk_global: new module [19.0][ADD] account_financial_risk_global: new module Apr 26, 2026
@carlosdauden

carlosdauden commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

I don’t think it’s necessary to create a new module for this; simply add a system parameter to the base module and propose the following change:

    @api.model
    def _get_risk_company_domain(self):
        if self.env['ir.config_parameter'].sudo().get_param('account_financial_risk.all_companies_risk'):
            return Domain.TRUE
        else:
            return [("company_id", "in", self.env.companies.ids)]

If you like, you can add an option in the settings to improve the user experience.

An even more powerful option would be to maintain a company-wide list of the companies for which risk is calculated.

    @api.model
    def _get_risk_company_domain(self):
        return [("company_id", "in", self.env.company.risk_related_companies.ids or self.env.companies.ids)]

@carlosdauden

Copy link
Copy Markdown
Contributor

ping @sergio-teruel

moduonbot pushed a commit to moduon/credit-control that referenced this pull request May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:account_financial_risk_global Module account_financial_risk_global series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants