Skip to content

Commit b4c3ccd

Browse files
TDukv1612
authored andcommitted
[IMP] account_move_tier_validation: send invoice validation
1 parent 745d2b0 commit b4c3ccd

15 files changed

+232
-3
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

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@
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+
"wizard/account_invoice_validation_send.xml",
20+
],
1621
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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">finance@cosanum.ch</field>
8+
<field name="partner_to">${object.user_validation_responsible_id.partner_id.id}</field>
9+
<field name="subject">Invoice for Approval</field>
10+
<!-- The body of the template has not been decided yet, except a button to open the invoice -->
11+
<field name="body_html" type="html">
12+
<div style="margin: 0px; padding: 0px;">
13+
<p style="margin: 0px; padding: 0px; font-size: 13px;">
14+
Here is a new vendor invoice to review:
15+
</p>
16+
17+
<table border="0" cellpadding="0" cellspacing="0" style="background-color:#505050; border:1px solid #353535; border-radius:5px;">
18+
<tr>
19+
<td align="center" valign="middle" 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;">
20+
21+
<a href="${object.get_web_url()}" style="color:#FFFFFF; text-decoration:none;">Invoice ${object.name}</a>
22+
</td>
23+
</tr>
24+
</table>
25+
26+
</div>
27+
</field>
28+
<field name="lang">${object.partner_id.lang}</field>
29+
<field name="auto_delete" eval="True"/>
30+
</record>
31+
32+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
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+
from werkzeug.urls import url_encode
5+
6+
from odoo import fields, models
57

68

79
class AccountMove(models.Model):
810
_name = "account.move"
911
_inherit = ["account.move", "tier.validation"]
1012
_state_from = ["draft"]
1113
_state_to = ["posted"]
14+
15+
user_validation_responsible_id = fields.Many2one(
16+
comodel_name="res.users", string="Validation Responsible"
17+
)
18+
19+
def get_web_url(self):
20+
self.ensure_one()
21+
base_url = self.env["ir.config_parameter"].get_param("web.base.url")
22+
url_params = url_encode(
23+
{
24+
"id": self.id,
25+
"view_type": "form",
26+
"model": "account.move",
27+
"menu_id": self.env.ref("account_accountant.menu_accounting").id,
28+
"action": self.env.ref("account.action_move_in_invoice_type").id,
29+
}
30+
)
31+
return f"{base_url}/web#{url_params}"

account_move_tier_validation/models/tier_definition.py

+7
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ def _get_tier_validation_model_names(self):
1212
res = super(TierDefinition, self)._get_tier_validation_model_names()
1313
res.append("account.move")
1414
return res
15+
16+
def request_validation(self):
17+
super().request_validation()
18+
action = self.env.ref(
19+
"account_move_tier_validation.invoice_send_validation_request"
20+
)
21+
return action.read()[0]
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 TestCosanumAccountMoveTierValidation(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

+9
Original file line numberDiff line numberDiff line change
@@ -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 @@
1+
from . import account_invoice_validation_send
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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(
32+
_("Invoice to request validation for has not been found")
33+
)
34+
composer = self.env['mail.compose.message'].create({})
35+
values = {
36+
'composition_mode': "mass_mail",
37+
'invoice_id': invoice.id,
38+
'composer_id': composer.id,
39+
}
40+
if invoice.user_validation_responsible_id:
41+
values["partner_ids"] = [
42+
(4, invoice.user_validation_responsible_id.partner_id.id, 0)
43+
]
44+
if hasattr(invoice, 'attachment_ids') and invoice.attachment_ids:
45+
values['attachment_ids'] = invoice.attachment_ids.ids
46+
res.update(values)
47+
return res
48+
49+
@api.onchange('template_id')
50+
def onchange_template_id(self):
51+
for wizard in self:
52+
if wizard.composer_id:
53+
wizard.composer_id.template_id = wizard.template_id.id
54+
wizard.composer_id.onchange_template_id_wrapper()
55+
56+
def send_action(self):
57+
self.ensure_one()
58+
if not self.partner_ids:
59+
raise ValidationError(_("An email recipient is required."))
60+
self.composer_id.send_mail()
61+
return {'type': 'ir.actions.act_window_close'}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 name="partner_ids" widget="many2many_tags_email" string="Recipients" placeholder="Add contacts to notify..." />
19+
<field name="subject" placeholder="Subject..." />
20+
</group>
21+
<field name="body" style="border:none;" options="{'style-inline': true}"/>
22+
</div>
23+
<group>
24+
<field name="attachment_ids" widget="many2many_binary" string="Attach a file" nolabel="1" colspan="2" />
25+
</group>
26+
</div>
27+
<footer>
28+
<button string="Send"
29+
name="send_action" type="object" class="send btn-primary o_mail_send"/>
30+
<button string="Cancel" class="btn-secondary" special="cancel" />
31+
</footer>
32+
</form>
33+
</field>
34+
</record>
35+
36+
<record id="invoice_send_validation_request" model="ir.actions.act_window">
37+
<field name="name">Send Validation Request</field>
38+
<field name="res_model">account.invoice.send.validation</field>
39+
<field name="binding_model_id" ref="model_account_move"/>
40+
<field name="binding_view_types">form</field>
41+
<field name="view_mode">form</field>
42+
<field name="target">new</field>
43+
<field name="groups_id" eval="[(4, ref('account.group_account_invoice'))]"/>
44+
<field name="context">{'default_template_id': ref('cosanum_account_move_tier_validation.email_template_validation_invoice'),}</field>
45+
</record>
46+
47+
</odoo>

0 commit comments

Comments
 (0)