diff --git a/sale_financial_risk/README.rst b/sale_financial_risk/README.rst index 0285681c8..3d74329c3 100644 --- a/sale_financial_risk/README.rst +++ b/sale_financial_risk/README.rst @@ -7,7 +7,7 @@ Sale Financial Risk !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:ea8927c83b428d46a09ec5731ed39bf3def893cc64a8904cc994621051da9e8b + !! source digest: sha256:c9f9d5930234f1dc3c7968f2c219181d293ee4195f970c7c0afccb742e1984b1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -41,6 +41,11 @@ If any limit is exceed the partner gets forbidden to confirm sale orders. .. contents:: :local: +Configuration +============= + +If you want an email to be sent when risk is exceeded in sale orders, go to *Invoicing/Accounting > Configuration > Settings > Financial Risk* and fill the field `Email template sent when confirming sale order risk`. + Usage ===== @@ -82,6 +87,10 @@ Contributors * Ugne Sinkeviciene +* `Aion Tech `_: + + * Simone Rubino + Maintainers ~~~~~~~~~~~ diff --git a/sale_financial_risk/__init__.py b/sale_financial_risk/__init__.py index 548c73eb1..3b78e7272 100644 --- a/sale_financial_risk/__init__.py +++ b/sale_financial_risk/__init__.py @@ -1,2 +1,3 @@ from .hooks import pre_init_hook from . import models +from . import wizards diff --git a/sale_financial_risk/models/__init__.py b/sale_financial_risk/models/__init__.py index 014f98900..cadf021f7 100644 --- a/sale_financial_risk/models/__init__.py +++ b/sale_financial_risk/models/__init__.py @@ -1,4 +1,5 @@ from . import payment +from . import res_company from . import res_partner from . import sale from . import res_config_settings diff --git a/sale_financial_risk/models/res_company.py b/sale_financial_risk/models/res_company.py new file mode 100644 index 000000000..dc7b31b92 --- /dev/null +++ b/sale_financial_risk/models/res_company.py @@ -0,0 +1,15 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + sale_order_confirm_risk_template_id = fields.Many2one( + comodel_name="mail.template", + string="Email template sent when confirming sale order risk", + help="This email template is sent when " + "the 'Partner risk exceeded wizard' for a sale order is confirmed.", + ) diff --git a/sale_financial_risk/models/res_config_settings.py b/sale_financial_risk/models/res_config_settings.py index 368e9de7e..f813ae10b 100644 --- a/sale_financial_risk/models/res_config_settings.py +++ b/sale_financial_risk/models/res_config_settings.py @@ -1,3 +1,4 @@ +# Copyright 2024 Simone Rubino - Aion Tech # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models @@ -9,3 +10,7 @@ class ResConfigSettings(models.TransientModel): "Include locked sale orders into risk calculation", config_parameter="sale_financial_risk.include_risk_sale_order_done", ) + sale_order_confirm_risk_template_id = fields.Many2one( + readonly=False, + related="company_id.sale_order_confirm_risk_template_id", + ) diff --git a/sale_financial_risk/readme/CONFIGURE.rst b/sale_financial_risk/readme/CONFIGURE.rst new file mode 100644 index 000000000..6457c39c7 --- /dev/null +++ b/sale_financial_risk/readme/CONFIGURE.rst @@ -0,0 +1 @@ +If you want an email to be sent when risk is exceeded in sale orders, go to *Invoicing/Accounting > Configuration > Settings > Financial Risk* and fill the field `Email template sent when confirming sale order risk`. diff --git a/sale_financial_risk/readme/CONTRIBUTORS.rst b/sale_financial_risk/readme/CONTRIBUTORS.rst index e1861b7ac..fd5886154 100644 --- a/sale_financial_risk/readme/CONTRIBUTORS.rst +++ b/sale_financial_risk/readme/CONTRIBUTORS.rst @@ -8,3 +8,7 @@ * Agathe Mollé * Ugne Sinkeviciene + +* `Aion Tech `_: + + * Simone Rubino diff --git a/sale_financial_risk/static/description/index.html b/sale_financial_risk/static/description/index.html index 3a28aa495..2358aa0d2 100644 --- a/sale_financial_risk/static/description/index.html +++ b/sale_financial_risk/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -366,7 +367,7 @@

Sale Financial Risk

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:ea8927c83b428d46a09ec5731ed39bf3def893cc64a8904cc994621051da9e8b +!! source digest: sha256:c9f9d5930234f1dc3c7968f2c219181d293ee4195f970c7c0afccb742e1984b1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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

Extends Partner Financial Risk to manage sales orders.

@@ -377,18 +378,23 @@

Sale Financial Risk

Table of contents

+
+

Configuration

+

If you want an email to be sent when risk is exceeded in sale orders, go to Invoicing/Accounting > Configuration > Settings > Financial Risk and fill the field Email template sent when confirming sale order risk.

+
-

Usage

+

Usage

To use this module, you need to:

  1. Go to Customers > Financial Risk
  2. @@ -397,7 +403,7 @@

    Usage

-

Bug Tracker

+

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 @@ -405,15 +411,15 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Tecnativa
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

diff --git a/sale_financial_risk/tests/test_partner_sale_risk.py b/sale_financial_risk/tests/test_partner_sale_risk.py index 63b3945e3..7adc33360 100644 --- a/sale_financial_risk/tests/test_partner_sale_risk.py +++ b/sale_financial_risk/tests/test_partner_sale_risk.py @@ -1,4 +1,5 @@ # Copyright 2016-2018 Tecnativa - Carlos Dauden +# Copyright 2024 Simone Rubino - Aion Tech # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import fields @@ -243,3 +244,35 @@ def test_manual_currency_risk_exceeded(self): # Limit exceeded self.assertNotEqual(result, True) self.assertEqual(result["res_model"], "partner.risk.exceeded.wiz") + + def test_confirm_risk_send_email(self): + """When the risk is confirmed by the user, an email is sent.""" + # Arrange + order = self.sale_order + order.action_confirm() + template_subject = "Risk exceeded" + template = self.env["mail.template"].create( + { + "name": "Test Risk exceeded template", + "model_id": self.env.ref("sale.model_sale_order").id, + "subject": template_subject, + } + ) + order.company_id.sale_order_confirm_risk_template_id = template + partner = order.partner_id + partner.risk_sale_order_include = True + partner.credit_limit = order.amount_total - 1 + # pre-condition + self.assertTrue(partner.risk_exception) + existing_emails = self.env["mail.mail"].search([]) + + # Act + risk_wizard_action = order.copy().action_confirm() + risk_wizard = self.env[risk_wizard_action["res_model"]].browse( + risk_wizard_action["res_id"] + ) + risk_wizard.button_continue() + + # Assert + new_emails = self.env["mail.mail"].search([]) - existing_emails + self.assertIn(template_subject, new_emails.mapped("subject")) diff --git a/sale_financial_risk/views/res_config_settings.xml b/sale_financial_risk/views/res_config_settings.xml index 9466bee47..64b4c685e 100644 --- a/sale_financial_risk/views/res_config_settings.xml +++ b/sale_financial_risk/views/res_config_settings.xml @@ -1,4 +1,6 @@ + res.config.settings.view.form.inherit.credit.control @@ -26,6 +28,32 @@
+ +
+
+
+
+
+ diff --git a/sale_financial_risk/wizards/__init__.py b/sale_financial_risk/wizards/__init__.py new file mode 100644 index 000000000..9c615081f --- /dev/null +++ b/sale_financial_risk/wizards/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import partner_risk_exceeded diff --git a/sale_financial_risk/wizards/partner_risk_exceeded.py b/sale_financial_risk/wizards/partner_risk_exceeded.py new file mode 100644 index 000000000..21f245e5f --- /dev/null +++ b/sale_financial_risk/wizards/partner_risk_exceeded.py @@ -0,0 +1,20 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class PartnerRiskExceededWiz(models.TransientModel): + _inherit = "partner.risk.exceeded.wiz" + + def _post_sale_order_confirm_risk(self, origin_record): + template = origin_record.company_id.sale_order_confirm_risk_template_id + if template: + template.send_mail(origin_record.id) + + def button_continue(self): + continue_result = super().button_continue() + origin_record = self.origin_reference + if origin_record._name == "sale.order": + self._post_sale_order_confirm_risk(origin_record) + return continue_result