Skip to content

Commit

Permalink
[17.0][MIG] account_financial_risk: Migration to 17.0
Browse files Browse the repository at this point in the history
Co-authored-by: sbiosca-s73 <sergi.biosca@studio73.es>
  • Loading branch information
Mat-moran and sbiosca-s73 committed May 27, 2024
1 parent fb0f7a0 commit fcddb80
Show file tree
Hide file tree
Showing 17 changed files with 193 additions and 186 deletions.
78 changes: 40 additions & 38 deletions account_financial_risk/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand All @@ -50,63 +52,63 @@ 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
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/credit-control/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 <https://github.com/OCA/credit-control/issues/new?body=module:%20account_financial_risk%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/credit-control/issues/new?body=module:%20account_financial_risk%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~
-------

* Tecnativa

Contributors
~~~~~~~~~~~~

* `Tecnativa <https://www.tecnativa.com>`_:

* Carlos Dauden
* Pedro M. Baeza
* Ernesto Tejeda
------------

* Agathe Mollé <agathe.molle@savoirfairelinux.com>
- `Tecnativa <https://www.tecnativa.com>`__:

* Ugne Sinkeviciene <ugne@versada.eu>
- Carlos Dauden
- Pedro M. Baeza
- Ernesto Tejeda

* `Ooops404 <https://www.ooops404.com>`__:
- Agathe Mollé <agathe.molle@savoirfairelinux.com>
- Ugne Sinkeviciene <ugne@versada.eu>
- `Ooops404 <https://www.ooops404.com>`__:

* Ilyas <irazor147@gmail.com>
- Ilyas <irazor147@gmail.com>

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -126,6 +128,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-carlosdauden|

This module is part of the `OCA/credit-control <https://github.com/OCA/credit-control/tree/16.0/account_financial_risk>`_ project on GitHub.
This module is part of the `OCA/credit-control <https://github.com/OCA/credit-control/tree/17.0/account_financial_risk>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion account_financial_risk/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
76 changes: 44 additions & 32 deletions account_financial_risk/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand All @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions account_financial_risk/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
8 changes: 8 additions & 0 deletions account_financial_risk/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 0 additions & 6 deletions account_financial_risk/readme/CONFIGURE.rst

This file was deleted.

8 changes: 8 additions & 0 deletions account_financial_risk/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- [Tecnativa](https://www.tecnativa.com):
- Carlos Dauden
- Pedro M. Baeza
- Ernesto Tejeda
- Agathe Mollé \<<agathe.molle@savoirfairelinux.com>\>
- Ugne Sinkeviciene \<<ugne@versada.eu>\>
- [Ooops404](https://www.ooops404.com):
- Ilyas \<<irazor147@gmail.com>\>
13 changes: 0 additions & 13 deletions account_financial_risk/readme/CONTRIBUTORS.rst

This file was deleted.

11 changes: 11 additions & 0 deletions account_financial_risk/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 0 additions & 11 deletions account_financial_risk/readme/DESCRIPTION.rst

This file was deleted.

12 changes: 12 additions & 0 deletions account_financial_risk/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 0 additions & 11 deletions account_financial_risk/readme/USAGE.rst

This file was deleted.

Loading

0 comments on commit fcddb80

Please sign in to comment.