diff --git a/account_financial_risk/README.rst b/account_financial_risk/README.rst index ff3edbba9..b4a286f89 100644 --- a/account_financial_risk/README.rst +++ b/account_financial_risk/README.rst @@ -17,28 +17,30 @@ Account Financial Risk :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcredit--control-lightgray.png?logo=github - :target: https://github.com/OCA/credit-control/tree/16.0/account_financial_risk + :target: https://github.com/OCA/credit-control/tree/17.0/account_financial_risk :alt: OCA/credit-control .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/credit-control-16-0/credit-control-16-0-account_financial_risk + :target: https://translation.odoo-community.org/projects/credit-control-17-0/credit-control-17-0-account_financial_risk :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png - :target: https://runboat.odoo-community.org/builds?repo=OCA/credit-control&target_branch=16.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/credit-control&target_branch=17.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| -Adds a new page in partner to manage its *Financial Risk*. -(Only visible for User or Manager Financial Risk groups) +Adds a new page in partner to manage its *Financial Risk*. (Only visible +for User or Manager Financial Risk groups) -If any limit is exceeded, you won't be able to confirm any of its invoices -unless you are authorized (Financial Risk Manager group). -You can click in risk amount to view amount origin. +If any limit is exceeded, you won't be able to confirm any of its +invoices unless you are authorized (Financial Risk Manager group). You +can click in risk amount to view amount origin. -.. figure:: https://raw.githubusercontent.com/OCA/credit-control/16.0/account_financial_risk/static/description/financial_risk_click.png +|image1| -When a non-zero credit limit is set, the last modification date is saved and -displayed next to the credit limit. +When a non-zero credit limit is set, the last modification date is saved +and displayed next to the credit limit. + +.. |image1| image:: https://raw.githubusercontent.com/OCA/credit-control/17.0/account_financial_risk/static/description/financial_risk_click.png **Table of contents** @@ -50,25 +52,27 @@ Configuration To configure this module, you need to: -#. Go to User and set group User or Manager Financial Risk -#. Go to *Invoicing/Accounting > Configuration > Settings > Accounting* -#. In the *Customer Payments* section, fill *Maturity Margin* for setting the - number of days to last after the due date to consider an invoice as unpaid. +1. Go to User and set group User or Manager Financial Risk +2. Go to *Invoicing/Accounting > Configuration > Settings > Accounting* +3. In the *Customer Payments* section, fill *Maturity Margin* for + setting the number of days to last after the due date to consider an + invoice as unpaid. Usage ===== To use this module, you need to: -#. Go to *Invoicing/Accounting > Customers > Customers*. -#. Select an existing customer or create a new one. -#. Open the *Financial Risk* tab. -#. Set limits and choose options to compute in credit limit. -#. Go to *Invoicing/Accounting > Customers > Invoices* and create new +1. Go to *Invoicing/Accounting > Customers > Customers*. +2. Select an existing customer or create a new one. +3. Open the *Financial Risk* tab. +4. Set limits and choose options to compute in credit limit. +5. Go to *Invoicing/Accounting > Customers > Invoices* and create new customer invoices. -#. Test the restriction trying to create an invoice for the partner for an - amount higher of the limit you have set. -#. Return to Customer *Financial Risk* tab and click in amount to view origin. +6. Test the restriction trying to create an invoice for the partner for + an amount higher of the limit you have set. +7. Return to Customer *Financial Risk* tab and click in amount to view + origin. Bug Tracker =========== @@ -76,7 +80,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -84,29 +88,27 @@ Credits ======= Authors -~~~~~~~ +------- * Tecnativa Contributors -~~~~~~~~~~~~ - -* `Tecnativa `_: - - * Carlos Dauden - * Pedro M. Baeza - * Ernesto Tejeda +------------ -* Agathe Mollé +- `Tecnativa `__: -* Ugne Sinkeviciene + - Carlos Dauden + - Pedro M. Baeza + - Ernesto Tejeda -* `Ooops404 `__: +- Agathe Mollé +- Ugne Sinkeviciene +- `Ooops404 `__: - * Ilyas + - Ilyas Maintainers -~~~~~~~~~~~ +----------- This module is maintained by the OCA. @@ -126,6 +128,6 @@ Current `maintainer `__: |maintainer-carlosdauden| -This module is part of the `OCA/credit-control `_ project on GitHub. +This module is part of the `OCA/credit-control `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_financial_risk/__manifest__.py b/account_financial_risk/__manifest__.py index ce5d21a8d..055911bf0 100644 --- a/account_financial_risk/__manifest__.py +++ b/account_financial_risk/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Account Financial Risk", "summary": "Manage customer risk", - "version": "16.0.1.2.2", + "version": "17.0.1.0.0", "category": "Accounting", "license": "AGPL-3", "author": "Tecnativa, Odoo Community Association (OCA)", diff --git a/account_financial_risk/models/res_partner.py b/account_financial_risk/models/res_partner.py index 1d7f1aab2..293e2c1b1 100644 --- a/account_financial_risk/models/res_partner.py +++ b/account_financial_risk/models/res_partner.py @@ -274,10 +274,8 @@ def _risk_account_groups(self): max_date = self._max_risk_date_due() company_domain = self._get_risk_company_domain() fields = [ - "partner_id", - "account_id", - "amount_residual", - "amount_residual_currency", + "amount_residual:sum", + "amount_residual_currency:sum", ] groupby = ["partner_id", "account_id", "currency_id"] return { @@ -350,12 +348,10 @@ def _compute_risk_account_amount(self): return # pragma: no cover groups = self._risk_account_groups() for _key, group in groups.items(): - group["read_group"] = self.env["account.move.line"].read_group( - group["domain"] + [("partner_id", "in", customers.ids)], - group["fields"], - group["group_by"], - orderby="id", - lazy=False, + group["read_group"] = self.env["account.move.line"]._read_group( + domain=group["domain"] + [("partner_id", "in", customers.ids)], + groupby=group["group_by"], + aggregates=group["fields"], ) for partner in customers: partner.update(partner._prepare_risk_account_vals(groups)) @@ -369,53 +365,69 @@ def _prepare_risk_account_vals(self, groups): "risk_account_amount_unpaid": 0.0, } # Partner receivable account determines if amount is in invoice field - for reg in groups["draft"]["read_group"]: - if reg["partner_id"][0] not in self.ids: + for ( + partner, + account, + currency, # noqa: B007 + amount_residual, + amount_residual_currency, # noqa: B007 + ) in groups["draft"]["read_group"]: + if partner.id not in self.ids: continue # pragma: no cover - account = self.env["account.account"].browse(reg["account_id"][0]) vals["risk_invoice_draft"] += account.company_id.currency_id._convert( - reg["amount_residual"], + amount_residual, self.risk_currency_id, account.company_id, fields.Date.context_today(self), round=False, ) - for reg in groups["open"]["read_group"]: - if reg["partner_id"][0] not in self.ids: + for ( + partner, + account, + currency, + amount_residual, + amount_residual_currency, + ) in groups["open"]["read_group"]: + if partner.id not in self.ids: continue # pragma: no cover - account = self.env["account.account"].browse(reg["account_id"][0]) - if self.property_account_receivable_id.id == reg["account_id"][0]: + if self.property_account_receivable_id.id == account.id: vals["risk_invoice_open"] += self._get_amount_in_risk_currency( - reg, account + currency, amount_residual_currency, amount_residual, account ) else: vals["risk_account_amount"] += self._get_amount_in_risk_currency( - reg, account + currency, amount_residual_currency, amount_residual, account ) - for reg in groups["unpaid"]["read_group"]: - if reg["partner_id"][0] not in self.ids: + for ( + partner, + account, + currency, + amount_residual, + amount_residual_currency, + ) in groups["unpaid"]["read_group"]: + if partner.id not in self.ids: continue # pragma: no cover - account = self.env["account.account"].browse(reg["account_id"][0]) - if self.property_account_receivable_id.id == reg["account_id"][0]: + if self.property_account_receivable_id.id == account.id: vals["risk_invoice_unpaid"] += self._get_amount_in_risk_currency( - reg, account + currency, amount_residual_currency, amount_residual, account ) else: vals["risk_account_amount_unpaid"] += self._get_amount_in_risk_currency( - reg, account + currency, amount_residual_currency, amount_residual, account ) return vals - def _get_amount_in_risk_currency(self, group, account): + def _get_amount_in_risk_currency( + self, currency, amount_residual_currency, amount_residual, account + ): acc_currency_id = account.company_id.currency_id.id risk_currency_id = self.risk_currency_id.id - group_currency_id = group["currency_id"][0] - if group_currency_id == risk_currency_id: - return group["amount_residual_currency"] + if currency.id == risk_currency_id: + return amount_residual_currency elif acc_currency_id == risk_currency_id: - return group["amount_residual"] + return amount_residual return account.company_id.currency_id._convert( - group["amount_residual"], + amount_residual, self.risk_currency_id, account.company_id, fields.Date.context_today(self), diff --git a/account_financial_risk/pyproject.toml b/account_financial_risk/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/account_financial_risk/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_financial_risk/readme/CONFIGURE.md b/account_financial_risk/readme/CONFIGURE.md new file mode 100644 index 000000000..c96424bb9 --- /dev/null +++ b/account_financial_risk/readme/CONFIGURE.md @@ -0,0 +1,8 @@ +To configure this module, you need to: + +1. Go to User and set group User or Manager Financial Risk +2. Go to *Invoicing/Accounting \> Configuration \> Settings \> + Accounting* +3. In the *Customer Payments* section, fill *Maturity Margin* for + setting the number of days to last after the due date to consider an + invoice as unpaid. diff --git a/account_financial_risk/readme/CONFIGURE.rst b/account_financial_risk/readme/CONFIGURE.rst deleted file mode 100644 index 159c01264..000000000 --- a/account_financial_risk/readme/CONFIGURE.rst +++ /dev/null @@ -1,6 +0,0 @@ -To configure this module, you need to: - -#. Go to User and set group User or Manager Financial Risk -#. Go to *Invoicing/Accounting > Configuration > Settings > Accounting* -#. In the *Customer Payments* section, fill *Maturity Margin* for setting the - number of days to last after the due date to consider an invoice as unpaid. diff --git a/account_financial_risk/readme/CONTRIBUTORS.md b/account_financial_risk/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..f667aa1f1 --- /dev/null +++ b/account_financial_risk/readme/CONTRIBUTORS.md @@ -0,0 +1,8 @@ +- [Tecnativa](https://www.tecnativa.com): + - Carlos Dauden + - Pedro M. Baeza + - Ernesto Tejeda +- Agathe Mollé \<\> +- Ugne Sinkeviciene \<\> +- [Ooops404](https://www.ooops404.com): + - Ilyas \<\> diff --git a/account_financial_risk/readme/CONTRIBUTORS.rst b/account_financial_risk/readme/CONTRIBUTORS.rst deleted file mode 100644 index c6275b002..000000000 --- a/account_financial_risk/readme/CONTRIBUTORS.rst +++ /dev/null @@ -1,13 +0,0 @@ -* `Tecnativa `_: - - * Carlos Dauden - * Pedro M. Baeza - * Ernesto Tejeda - -* Agathe Mollé - -* Ugne Sinkeviciene - -* `Ooops404 `__: - - * Ilyas diff --git a/account_financial_risk/readme/DESCRIPTION.md b/account_financial_risk/readme/DESCRIPTION.md new file mode 100644 index 000000000..c19dc5160 --- /dev/null +++ b/account_financial_risk/readme/DESCRIPTION.md @@ -0,0 +1,11 @@ +Adds a new page in partner to manage its *Financial Risk*. (Only visible +for User or Manager Financial Risk groups) + +If any limit is exceeded, you won't be able to confirm any of its +invoices unless you are authorized (Financial Risk Manager group). You +can click in risk amount to view amount origin. + +![](../static/description/financial_risk_click.png) + +When a non-zero credit limit is set, the last modification date is saved +and displayed next to the credit limit. diff --git a/account_financial_risk/readme/DESCRIPTION.rst b/account_financial_risk/readme/DESCRIPTION.rst deleted file mode 100644 index 73642e538..000000000 --- a/account_financial_risk/readme/DESCRIPTION.rst +++ /dev/null @@ -1,11 +0,0 @@ -Adds a new page in partner to manage its *Financial Risk*. -(Only visible for User or Manager Financial Risk groups) - -If any limit is exceeded, you won't be able to confirm any of its invoices -unless you are authorized (Financial Risk Manager group). -You can click in risk amount to view amount origin. - -.. figure:: ../static/description/financial_risk_click.png - -When a non-zero credit limit is set, the last modification date is saved and -displayed next to the credit limit. diff --git a/account_financial_risk/readme/USAGE.md b/account_financial_risk/readme/USAGE.md new file mode 100644 index 000000000..e4ec4a46e --- /dev/null +++ b/account_financial_risk/readme/USAGE.md @@ -0,0 +1,12 @@ +To use this module, you need to: + +1. Go to *Invoicing/Accounting \> Customers \> Customers*. +2. Select an existing customer or create a new one. +3. Open the *Financial Risk* tab. +4. Set limits and choose options to compute in credit limit. +5. Go to *Invoicing/Accounting \> Customers \> Invoices* and create new + customer invoices. +6. Test the restriction trying to create an invoice for the partner for + an amount higher of the limit you have set. +7. Return to Customer *Financial Risk* tab and click in amount to view + origin. diff --git a/account_financial_risk/readme/USAGE.rst b/account_financial_risk/readme/USAGE.rst deleted file mode 100644 index da366ea4a..000000000 --- a/account_financial_risk/readme/USAGE.rst +++ /dev/null @@ -1,11 +0,0 @@ -To use this module, you need to: - -#. Go to *Invoicing/Accounting > Customers > Customers*. -#. Select an existing customer or create a new one. -#. Open the *Financial Risk* tab. -#. Set limits and choose options to compute in credit limit. -#. Go to *Invoicing/Accounting > Customers > Invoices* and create new - customer invoices. -#. Test the restriction trying to create an invoice for the partner for an - amount higher of the limit you have set. -#. Return to Customer *Financial Risk* tab and click in amount to view origin. diff --git a/account_financial_risk/static/description/index.html b/account_financial_risk/static/description/index.html index 956d0a1de..81770b5bf 100644 --- a/account_financial_risk/static/description/index.html +++ b/account_financial_risk/static/description/index.html @@ -1,4 +1,3 @@ - @@ -369,17 +368,15 @@

Account Financial Risk

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:e81b96f2a825ac1d5a813a977d901282590efdf6736885168b6da4fd5eebcb86 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/credit-control Translate me on Weblate Try me on Runboat

-

Adds a new page in partner to manage its Financial Risk. -(Only visible for User or Manager Financial Risk groups)

-

If any limit is exceeded, you won’t be able to confirm any of its invoices -unless you are authorized (Financial Risk Manager group). -You can click in risk amount to view amount origin.

-
-https://raw.githubusercontent.com/OCA/credit-control/16.0/account_financial_risk/static/description/financial_risk_click.png -
-

When a non-zero credit limit is set, the last modification date is saved and -displayed next to the credit limit.

+

Beta License: AGPL-3 OCA/credit-control Translate me on Weblate Try me on Runboat

+

Adds a new page in partner to manage its Financial Risk. (Only visible +for User or Manager Financial Risk groups)

+

If any limit is exceeded, you won’t be able to confirm any of its +invoices unless you are authorized (Financial Risk Manager group). You +can click in risk amount to view amount origin.

+

image1

+

When a non-zero credit limit is set, the last modification date is saved +and displayed next to the credit limit.

Table of contents

    @@ -400,8 +397,9 @@

    Configuration

    1. Go to User and set group User or Manager Financial Risk
    2. Go to Invoicing/Accounting > Configuration > Settings > Accounting
    3. -
    4. In the Customer Payments section, fill Maturity Margin for setting the -number of days to last after the due date to consider an invoice as unpaid.
    5. +
    6. In the Customer Payments section, fill Maturity Margin for +setting the number of days to last after the due date to consider an +invoice as unpaid.
@@ -414,9 +412,10 @@

Usage

  • Set limits and choose options to compute in credit limit.
  • Go to Invoicing/Accounting > Customers > Invoices and create new customer invoices.
  • -
  • Test the restriction trying to create an invoice for the partner for an -amount higher of the limit you have set.
  • -
  • Return to Customer Financial Risk tab and click in amount to view origin.
  • +
  • Test the restriction trying to create an invoice for the partner for +an amount higher of the limit you have set.
  • +
  • Return to Customer Financial Risk tab and click in amount to view +origin.
  • @@ -424,7 +423,7 @@

    Bug Tracker

    Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -feedback.

    +feedback.

    Do not contact contributors directly about support or help with technical issues.

    @@ -461,7 +460,7 @@

    Maintainers

    promote its widespread use.

    Current maintainer:

    carlosdauden

    -

    This module is part of the OCA/credit-control project on GitHub.

    +

    This module is part of the OCA/credit-control project on GitHub.

    You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

    diff --git a/account_financial_risk/tests/test_account_financial_risk.py b/account_financial_risk/tests/test_account_financial_risk.py index 45840cc45..27277e1c2 100644 --- a/account_financial_risk/tests/test_account_financial_risk.py +++ b/account_financial_risk/tests/test_account_financial_risk.py @@ -13,14 +13,13 @@ class TestPartnerFinancialRisk(TransactionCase): @classmethod def setUpClass(cls): - super(TestPartnerFinancialRisk, cls).setUpClass() + super().setUpClass() cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT)) (cls.env.ref("base.USD") | cls.env.ref("base.EUR")).active = True cls.env.user.groups_id |= cls.env.ref("account.group_account_manager") cls.env.user.groups_id |= cls.env.ref( "account_financial_risk.group_account_financial_risk_manager" ) - tax_group_taxes = cls.env.ref("account.tax_group_taxes") main_company = cls.env.ref("base.main_company") cls.cr.execute( "UPDATE res_company SET currency_id = %s WHERE id = %s", @@ -77,7 +76,14 @@ def setUpClass(cls): { "name": "Tax for sale 10%", "type_tax_use": "sale", - "tax_group_id": tax_group_taxes.id, + "tax_group_id": cls.env["account.tax.group"] + .with_company(cls.env.company.id) + .create( + { + "name": "Tax Group TEST", + } + ) + .id, "amount_type": "percent", "amount": 10.0, } diff --git a/account_financial_risk/views/res_config_view.xml b/account_financial_risk/views/res_config_view.xml index 9f085226f..6f4b7a4c7 100644 --- a/account_financial_risk/views/res_config_view.xml +++ b/account_financial_risk/views/res_config_view.xml @@ -10,42 +10,30 @@ -

    Financial Risk

    -
    -
    -
    -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    + + + + + + + + diff --git a/account_financial_risk/views/res_partner_view.xml b/account_financial_risk/views/res_partner_view.xml index 62fc137ee..8297ce0df 100644 --- a/account_financial_risk/views/res_partner_view.xml +++ b/account_financial_risk/views/res_partner_view.xml @@ -12,7 +12,7 @@ @@ -25,7 +25,7 @@ >