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

[IMP] sale_financial_risk: Send email when risk confirmed #394

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion sale_financial_risk/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
=====

Expand Down Expand Up @@ -82,6 +87,10 @@ Contributors

* Ugne Sinkeviciene <ugne@versada.eu>

* `Aion Tech <https://aiontech.company/>`_:

* Simone Rubino <simone.rubino@aion-tech.it>

Maintainers
~~~~~~~~~~~

Expand Down
1 change: 1 addition & 0 deletions sale_financial_risk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .hooks import pre_init_hook
from . import models
from . import wizards
1 change: 1 addition & 0 deletions sale_financial_risk/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import payment
from . import res_company
from . import res_partner
from . import sale
from . import res_config_settings
15 changes: 15 additions & 0 deletions sale_financial_risk/models/res_company.py
Original file line number Diff line number Diff line change
@@ -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.",
)
5 changes: 5 additions & 0 deletions sale_financial_risk/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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",
)
1 change: 1 addition & 0 deletions sale_financial_risk/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -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`.
4 changes: 4 additions & 0 deletions sale_financial_risk/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
* Agathe Mollé <agathe.molle@savoirfairelinux.com>

* Ugne Sinkeviciene <ugne@versada.eu>

* `Aion Tech <https://aiontech.company/>`_:

* Simone Rubino <simone.rubino@aion-tech.it>
46 changes: 29 additions & 17 deletions sale_financial_risk/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">Sale Financial Risk</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ea8927c83b428d46a09ec5731ed39bf3def893cc64a8904cc994621051da9e8b
!! source digest: sha256:c9f9d5930234f1dc3c7968f2c219181d293ee4195f970c7c0afccb742e1984b1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/credit-control/tree/16.0/sale_financial_risk"><img alt="OCA/credit-control" src="https://img.shields.io/badge/github-OCA%2Fcredit--control-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/credit-control-16-0/credit-control-16-0-sale_financial_risk"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/credit-control&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Extends Partner Financial Risk to manage sales orders.</p>
Expand All @@ -377,18 +378,23 @@ <h1 class="title">Sale Financial Risk</h1>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>If you want an email to be sent when risk is exceeded in sale orders, go to <em>Invoicing/Accounting &gt; Configuration &gt; Settings &gt; Financial Risk</em> and fill the field <cite>Email template sent when confirming sale order risk</cite>.</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>To use this module, you need to:</p>
<ol class="arabic simple">
<li>Go to <em>Customers &gt; Financial Risk</em></li>
Expand All @@ -397,23 +403,23 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
</ol>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/credit-control/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/credit-control/issues/new?body=module:%20sale_financial_risk%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Carlos Dauden</li>
Expand All @@ -424,12 +430,18 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
</li>
<li>Agathe Mollé &lt;<a class="reference external" href="mailto:agathe.molle&#64;savoirfairelinux.com">agathe.molle&#64;savoirfairelinux.com</a>&gt;</li>
<li>Ugne Sinkeviciene &lt;<a class="reference external" href="mailto:ugne&#64;versada.eu">ugne&#64;versada.eu</a>&gt;</li>
<li><a class="reference external" href="https://aiontech.company/">Aion Tech</a>:<ul>
<li>Simone Rubino &lt;<a class="reference external" href="mailto:simone.rubino&#64;aion-tech.it">simone.rubino&#64;aion-tech.it</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
Expand Down
33 changes: 33 additions & 0 deletions sale_financial_risk/tests/test_partner_sale_risk.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"))
28 changes: 28 additions & 0 deletions sale_financial_risk/views/res_config_settings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 Simone Rubino - Aion Tech
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.credit.control</field>
Expand Down Expand Up @@ -26,6 +28,32 @@
</div>
</div>
</xpath>
<xpath
expr="//field[@name='allow_overrisk_invoice_validation']/../.."
position="after"
>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane" />
<div class="o_setting_right_pane">
<label for="sale_order_confirm_risk_template_id" />
<span
class="fa fa-lg fa-building-o"
title="Values set here are company-specific."
role="img"
aria-label="Values set here are company-specific."
groups="base.group_multi_company"
/>
<div class="text-muted">
This email template is sent when the 'Partner risk exceeded wizard' for a sale order is confirmed.
</div>
<div class="content-group">
<div class="row mt16 ml4">
<field name="sale_order_confirm_risk_template_id" />
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>
3 changes: 3 additions & 0 deletions sale_financial_risk/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import partner_risk_exceeded
20 changes: 20 additions & 0 deletions sale_financial_risk/wizards/partner_risk_exceeded.py
Original file line number Diff line number Diff line change
@@ -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
Loading