Skip to content

Commit e1ab6cf

Browse files
TDukv1612
authored andcommittedDec 17, 2021
[IMP] account_move_tier_validation: send invoice validation
[IMP] account_move_tier_validation: send invoice validation
1 parent 745d2b0 commit e1ab6cf

16 files changed

+297
-5
lines changed
 

‎account_move_tier_validation/README.rst

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ Contributors
8383

8484
* Odoo Perú <info@odooperu.pe>
8585
* Tharathip Chaweewongphan <tharathipc@ecosoft.co.th>
86+
* Thierry Ducrest <thierry.ducrest@camptocamp.com>
87+
* `Trobz <https://trobz.com>`_:
88+
* Khoi Vo <khoivha@trobz.com>
8689

8790
Maintainers
8891
~~~~~~~~~~~

‎account_move_tier_validation/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
33

44
from . import models
5+
from . import wizard

‎account_move_tier_validation/__manifest__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@
1212
"application": False,
1313
"installable": True,
1414
"depends": ["account", "base_tier_validation"],
15-
"data": ["views/account_move_view.xml"],
15+
"data": [
16+
"data/mail_template_data.xml",
17+
"security/ir.model.access.csv",
18+
"views/account_move_view.xml",
19+
"views/tier_definition_view.xml",
20+
"wizard/account_invoice_validation_send.xml",
21+
],
1622
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" ?>
2+
<odoo>
3+
4+
<record id="email_template_validation_invoice" model="mail.template">
5+
<field name="name">Account Invoice Validation Request</field>
6+
<field name="model_id" ref="account.model_account_move" />
7+
<field name="email_from">${(object.company_id.email)}</field>
8+
<field
9+
name="partner_to"
10+
>${object.user_validation_responsible_id.partner_id.id}</field>
11+
<field name="subject">Invoice for Approval</field>
12+
<!-- The body of the template has not been decided yet, except a button to open the invoice -->
13+
<field name="body_html" type="html">
14+
<div style="margin: 0px; padding: 0px;">
15+
<p style="margin: 0px; padding: 0px; font-size: 13px;">
16+
Here is a new vendor invoice to review:
17+
</p>
18+
19+
<table
20+
border="0"
21+
cellpadding="0"
22+
cellspacing="0"
23+
style="background-color:#505050; border:1px solid #353535; border-radius:5px;"
24+
>
25+
<tr>
26+
<td
27+
align="center"
28+
valign="middle"
29+
style="color:#FFFFFF; font-family:Helvetica, Arial, sans-serif; font-size:16px; font-weight:bold; letter-spacing:-.5px; line-height:150%; padding-top:15px; padding-right:30px; padding-bottom:15px; padding-left:30px;"
30+
>
31+
32+
<a
33+
href="${object.get_web_url()}"
34+
style="color:#FFFFFF; text-decoration:none;"
35+
>Invoice ${object.name}</a>
36+
</td>
37+
</tr>
38+
</table>
39+
40+
</div>
41+
</field>
42+
<field name="lang">${object.partner_id.lang}</field>
43+
<field name="auto_delete" eval="True" />
44+
</record>
45+
46+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,48 @@
11
# Copyright <2020> PESOL <info@pesol.es>
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
33

4-
from odoo import models
4+
5+
from werkzeug.urls import url_encode
6+
7+
from odoo import fields, models
58

69

710
class AccountMove(models.Model):
811
_name = "account.move"
912
_inherit = ["account.move", "tier.validation"]
1013
_state_from = ["draft"]
1114
_state_to = ["posted"]
15+
16+
user_validation_responsible_id = fields.Many2one(
17+
comodel_name="res.users", string="Validation Responsible"
18+
)
19+
20+
def button_request_validation(self):
21+
for account_move in self:
22+
res = super().request_validation()
23+
tier_definitions = self.env["tier.definition"].search(
24+
[
25+
("model", "=", "account.move"),
26+
("open_mail_composer_wizard", "=", True),
27+
]
28+
)
29+
for td in tier_definitions:
30+
if account_move.evaluate_tier(td):
31+
action = self.env.ref(
32+
"account_move_tier_validation.invoice_send_validation_request"
33+
)
34+
return action.read()[0]
35+
return res
36+
37+
def get_web_url(self):
38+
self.ensure_one()
39+
base_url = self.env["ir.config_parameter"].get_param("web.base.url")
40+
url_params = url_encode(
41+
{
42+
"id": self.id,
43+
"view_type": "form",
44+
"model": "account.move",
45+
"action": self.env.ref("account.action_move_in_invoice_type").id,
46+
}
47+
)
48+
return f"{base_url}/web#{url_params}"

‎account_move_tier_validation/models/tier_definition.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Copyright <2020> PESOL <info@pesol.es>
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
33

4-
from odoo import api, models
4+
from odoo import api, fields, models
55

66

77
class TierDefinition(models.Model):
88
_inherit = "tier.definition"
99

10+
open_mail_composer_wizard = fields.Boolean(
11+
"Open Mail Composer Wizard when Requesting Validation",
12+
)
13+
1014
@api.model
1115
def _get_tier_validation_model_names(self):
1216
res = super(TierDefinition, self)._get_tier_validation_model_names()
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
* Odoo Perú <info@odooperu.pe>
22
* Tharathip Chaweewongphan <tharathipc@ecosoft.co.th>
3+
* Thierry Ducrest <thierry.ducrest@camptocamp.com>
4+
* `Trobz <https://trobz.com>`_:
5+
* Khoi Vo <khoivha@trobz.com>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_account_invoice_send_validation,access_account_invoice_send_validation,model_account_invoice_send_validation,,1,1,1,1

‎account_move_tier_validation/static/description/index.html

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6-
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
6+
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
77
<title>Account Move Tier Validation</title>
88
<style type="text/css">
99

@@ -432,6 +432,15 @@ <h2><a class="toc-backref" href="#id7">Contributors</a></h2>
432432
<ul class="simple">
433433
<li>Odoo Perú &lt;<a class="reference external" href="mailto:info&#64;odooperu.pe">info&#64;odooperu.pe</a>&gt;</li>
434434
<li>Tharathip Chaweewongphan &lt;<a class="reference external" href="mailto:tharathipc&#64;ecosoft.co.th">tharathipc&#64;ecosoft.co.th</a>&gt;</li>
435+
<li>Thierry Ducrest &lt;<a class="reference external" href="mailto:thierry.ducrest&#64;camptocamp.com">thierry.ducrest&#64;camptocamp.com</a>&gt;</li>
436+
<li><dl class="first docutils">
437+
<dt><a class="reference external" href="https://trobz.com">Trobz</a>:</dt>
438+
<dd><ul class="first last">
439+
<li>Khoi Vo &lt;<a class="reference external" href="mailto:khoivha&#64;trobz.com">khoivha&#64;trobz.com</a>&gt;</li>
440+
</ul>
441+
</dd>
442+
</dl>
443+
</li>
435444
</ul>
436445
</div>
437446
<div class="section" id="maintainers">

‎account_move_tier_validation/tests/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
from . import common
44
from . import test_tier_validation
5+
from . import test_account_move_tier_validation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2021 Camptocamp SA
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl)
3+
from odoo.tests import SavepointCase
4+
5+
6+
class TestAccountMoveTierValidation(SavepointCase):
7+
@classmethod
8+
def setUpClass(cls):
9+
super().setUpClass()
10+
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
11+
cls.user = cls.env.ref("base.user_demo")
12+
cls.invoice = cls.env["account.move"].create(
13+
{
14+
"move_type": "out_invoice",
15+
"user_validation_responsible_id": cls.user.id,
16+
}
17+
)
18+
19+
cls.wizard = (
20+
cls.env["account.invoice.send.validation"]
21+
.with_context({"active_ids": cls.invoice.ids})
22+
.create({})
23+
)
24+
25+
def test_wizard(self):
26+
"""Check the wizard works."""
27+
self.assertEqual(self.wizard.composition_mode, "mass_mail")
28+
self.assertTrue(self.user.partner_id in self.wizard.partner_ids)

‎account_move_tier_validation/views/account_move_view.xml

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<field name="arch" type="xml">
1010
<button name="action_post" position="before">
1111
<button
12-
name="request_validation"
12+
name="button_request_validation"
1313
string="Request Validation"
1414
attrs="{'invisible': ['|','|',('need_validation', '!=', True),('rejected','=',True),('state','not in',['draft'])]}"
1515
type="object"
@@ -80,6 +80,15 @@
8080
attrs="{'invisible':[('review_ids', '=', [])]}"
8181
/>
8282
</xpath>
83+
<xpath expr="//group[@id='other_tab_group']" position="inside">
84+
<group
85+
string="Validation"
86+
name="tier_validation"
87+
attrs="{'invisible': [('move_type', 'not in', ('in_invoice', 'in_refund'))]}"
88+
>
89+
<field name="user_validation_responsible_id" />
90+
</group>
91+
</xpath>
8392
</field>
8493
</record>
8594
<record id="view_account_invoice_filter" model="ir.ui.view">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="tier_definition_view_form_inherit" model="ir.ui.view">
4+
<field name="name">tier.definition.view.form.inherit</field>
5+
<field name="model">tier.definition</field>
6+
<field name="inherit_id" ref="base_tier_validation.tier_definition_view_form" />
7+
<field name="arch" type="xml">
8+
<field name="has_comment" position="after">
9+
<field
10+
name="open_mail_composer_wizard"
11+
attrs="{'invisible':[('model','!=','account.move')]}"
12+
/>
13+
</field>
14+
</field>
15+
</record>
16+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import account_invoice_validation_send
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2021 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
4+
from odoo import _, api, fields, models
5+
from odoo.exceptions import UserError, ValidationError
6+
from odoo.fields import first
7+
8+
9+
class AccountInvoiceSendValidation(models.TransientModel):
10+
_name = "account.invoice.send.validation"
11+
_inherits = {"mail.compose.message": "composer_id"}
12+
_description = "Account Invoice Send Validation Request"
13+
14+
invoice_id = fields.Many2one("account.move", string="Invoice")
15+
composer_id = fields.Many2one(
16+
"mail.compose.message",
17+
string="Composer",
18+
required=True,
19+
ondelete="cascade",
20+
)
21+
template_id = fields.Many2one(
22+
"mail.template", index=True, domain="[('model', '=', 'account.move')]"
23+
)
24+
25+
@api.model
26+
def default_get(self, fields):
27+
res = super().default_get(fields)
28+
res_ids = self._context.get("active_ids")
29+
invoice = first(self.env["account.move"].browse(res_ids))
30+
if not invoice:
31+
raise UserError(_("Invoice to request validation for has not been found"))
32+
composer = self.env["mail.compose.message"].create({})
33+
values = {
34+
"composition_mode": "mass_mail",
35+
"invoice_id": invoice.id,
36+
"composer_id": composer.id,
37+
}
38+
if invoice.user_validation_responsible_id:
39+
values["partner_ids"] = [
40+
(4, invoice.user_validation_responsible_id.partner_id.id, 0)
41+
]
42+
if hasattr(invoice, "attachment_ids") and invoice.attachment_ids:
43+
values["attachment_ids"] = invoice.attachment_ids.ids
44+
res.update(values)
45+
return res
46+
47+
@api.onchange("template_id")
48+
def onchange_template_id(self):
49+
for wizard in self:
50+
if wizard.composer_id:
51+
wizard.composer_id.template_id = wizard.template_id.id
52+
wizard.composer_id.onchange_template_id_wrapper()
53+
54+
def send_action(self):
55+
self.ensure_one()
56+
if not self.partner_ids:
57+
raise ValidationError(_("An email recipient is required."))
58+
self.composer_id.send_mail()
59+
return {"type": "ir.actions.act_window_close"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
4+
<record id="account_invoice_send_validation_form" model="ir.ui.view">
5+
<field name="name">account.invoice.send.validation.form</field>
6+
<field name="model">account.invoice.send.validation</field>
7+
<field name="groups_id" eval="[(4,ref('base.group_user'))]" />
8+
<field name="arch" type="xml">
9+
<form string="Invoice send validation request">
10+
<field name="composition_mode" invisible="1" />
11+
<field name="invoice_id" invisible="1" />
12+
<field name="email_from" invisible="1" />
13+
<field name="mail_server_id" invisible="1" />
14+
<field name="template_id" invisible="1" />
15+
<div name="mail_form">
16+
<div>
17+
<group>
18+
<field
19+
name="partner_ids"
20+
widget="many2many_tags_email"
21+
string="Recipients"
22+
placeholder="Add contacts to notify..."
23+
/>
24+
<field name="subject" placeholder="Subject..." />
25+
</group>
26+
<field name="body" style="border:none;" options="{'style-inline': true}" />
27+
</div>
28+
<group>
29+
<field
30+
name="attachment_ids"
31+
widget="many2many_binary"
32+
string="Attach a file"
33+
nolabel="1"
34+
colspan="2"
35+
/>
36+
</group>
37+
</div>
38+
<footer>
39+
<button
40+
string="Send"
41+
name="send_action"
42+
type="object"
43+
class="send btn-primary o_mail_send"
44+
/>
45+
<button string="Cancel" class="btn-secondary" special="cancel" />
46+
</footer>
47+
</form>
48+
</field>
49+
</record>
50+
51+
<record id="invoice_send_validation_request" model="ir.actions.act_window">
52+
<field name="name">Send Validation Request</field>
53+
<field name="res_model">account.invoice.send.validation</field>
54+
<field name="binding_model_id" ref="model_account_move" />
55+
<field name="binding_view_types">form</field>
56+
<field name="view_mode">form</field>
57+
<field name="target">new</field>
58+
<field name="groups_id" eval="[(4, ref('account.group_account_invoice'))]" />
59+
<field
60+
name="context"
61+
eval="{
62+
'default_template_id': ref('account_move_tier_validation.email_template_validation_invoice'),
63+
}"
64+
/>
65+
</record>
66+
67+
</odoo>

0 commit comments

Comments
 (0)
Please sign in to comment.