mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[ADD] account_payment_order_vendor_email
This commit is contained in:
committed by
Murtaza Mithaiwala
parent
70e78068e6
commit
b672adaeeb
59
account_payment_order_vendor_email/README.rst
Normal file
59
account_payment_order_vendor_email/README.rst
Normal file
@@ -0,0 +1,59 @@
|
||||
==================================
|
||||
Account Payment Order Vender Email
|
||||
==================================
|
||||
|
||||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
Add fields to Account Payment Mode.
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
Add `send_email_to_partner` on Account Payment Mode records.
|
||||
|
||||
Add 'email_temp_id' on Account Payment Mode records.
|
||||
|
||||
Add Email templated to send the Payment Details on Mail
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Authors
|
||||
~~~~~~~
|
||||
|
||||
* Thinkwell Designs
|
||||
|
||||
Contributors
|
||||
~~~~~~~~~~~~
|
||||
|
||||
* Murtaza Mithaiwala <mmithaiwala@opensourceintegrators.com>
|
||||
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
|
||||
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
.. image:: https://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: https://odoo-community.org
|
||||
|
||||
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.
|
||||
|
||||
This module is part of the `OCA/l10n-usa <https://github.com/OCA/bank-payment/tree/14.0/account_payment_order_vendor_email>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
1
account_payment_order_vendor_email/__init__.py
Normal file
1
account_payment_order_vendor_email/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
19
account_payment_order_vendor_email/__manifest__.py
Normal file
19
account_payment_order_vendor_email/__manifest__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Copyright (C) 2020 Open Source Integrators
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
"name": "Account Payment Order Email",
|
||||
"version": "14.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Open Source Integrators, Odoo Community Association (OCA)",
|
||||
"maintainers": [],
|
||||
"website": "https://github.com/OCA/bank-payment",
|
||||
"category": "Accounting",
|
||||
"depends": ["account_payment_order", "account_payment_mode"],
|
||||
"data": [
|
||||
"data/mail_template.xml",
|
||||
"views/account_payment_mode_view.xml",
|
||||
"views/account_payment_order_view.xml",
|
||||
],
|
||||
"installable": True,
|
||||
}
|
||||
252
account_payment_order_vendor_email/data/mail_template.xml
Normal file
252
account_payment_order_vendor_email/data/mail_template.xml
Normal file
@@ -0,0 +1,252 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo noupdate="1">
|
||||
|
||||
<record id="ach_payment_email_template" model="mail.template">
|
||||
<field name="name">Email for ACH Payments</field>
|
||||
<field
|
||||
name="model_id"
|
||||
ref="account_payment_order.model_account_payment_order"
|
||||
/>
|
||||
<field
|
||||
name="email_from"
|
||||
>${object.company_id.name | safe} <${(object.company_id.email or user.email) | safe}></field>
|
||||
<field name="email_cc" />
|
||||
<field name="subject">Remittance Advice</field>
|
||||
<field name="auto_delete" eval="True" />
|
||||
<field name="lang">${object.generated_user_id.lang}</field>
|
||||
<field
|
||||
name="body_html"
|
||||
><![CDATA[
|
||||
<table
|
||||
border="0"
|
||||
cellpadding="0"
|
||||
cellspacing="0"
|
||||
style="padding-top: 16px; background-color: white; font-family:Verdana, Arial,sans-serif; color: #454748; min-width:800px; border-collapse:separate;"
|
||||
><tr><td align="center">
|
||||
<table
|
||||
border="0"
|
||||
cellpadding="0"
|
||||
cellspacing="0"
|
||||
width="800"
|
||||
style="padding: 16px; background-color: white; color: #454748; border-collapse:separate;"
|
||||
>
|
||||
</table>
|
||||
</td></tr>
|
||||
<tbody>
|
||||
<!-- HEADER -->
|
||||
<tr>
|
||||
<td align="center" style="min-width: 800px;">
|
||||
<table
|
||||
border="0"
|
||||
cellpadding="0"
|
||||
cellspacing="0"
|
||||
width="590"
|
||||
style="min-width: 800px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:collapse;"
|
||||
>
|
||||
<tr><td style="min-width:750px;" valign="middle">
|
||||
<span style="font-size: 10px;">Remittance
|
||||
Advice</span><br/>
|
||||
<span
|
||||
style="font-size: 20px; font-weight: bold;"
|
||||
>
|
||||
${object.name}
|
||||
</span>
|
||||
</td><td valign="middle" align="right">
|
||||
<img
|
||||
src="/logo.png?company=${object.company_id.id}"
|
||||
style="padding: 0px; margin: 0px; height: auto; width: 80px;"
|
||||
alt="${object.company_id.name}"
|
||||
/>
|
||||
</td></tr>
|
||||
<tr><td colspan="2" style="text-align:center;min-width:750px;"">
|
||||
<hr
|
||||
width="100%"
|
||||
style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;"
|
||||
/>
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" style="min-width: 800px;">
|
||||
<table
|
||||
border="0"
|
||||
cellpadding="0"
|
||||
cellspacing="0"
|
||||
width="590"
|
||||
style="min-width: 800px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:collapse;"
|
||||
>
|
||||
<tr><td valign="top" style="font-size: 13px;">
|
||||
<div>
|
||||
Dear ${object.name},<br/><br/>
|
||||
A payment was processed on ${ctx['date']}
|
||||
for ${ctx['partner_name']} in the amount of
|
||||
${ctx['total_amount']} with reference
|
||||
${ctx['payment_ref']}.<br/><br/>
|
||||
% set line_dict = ctx.get('line_data',False)
|
||||
% for line in line_dict:
|
||||
<table style="min-width:800px;background-color: white; padding: 0px 8px 0px 8px; border-collapse: collapse;" width="800">
|
||||
<tr>
|
||||
<td style="border:1px solid #000000;width:80px; min-width:80px; max-width: 80px;">
|
||||
% if line == line_dict[0]:
|
||||
<b>
|
||||
${line.get("inv_date") or ''}
|
||||
</b>
|
||||
% else:
|
||||
${line.get("inv_date") or ''}
|
||||
% endif
|
||||
</td>
|
||||
<td style="border:1px solid #000000;width:150px; min-width:150px; max-width: 150px;" >
|
||||
% if line == line_dict[0]:
|
||||
<b>
|
||||
${line.get("inv_no") or ''}
|
||||
</b>
|
||||
% else:
|
||||
${line.get("inv_no") or ''}
|
||||
% endif
|
||||
</td>
|
||||
<td style="border:1px solid #000000;width:70px; min-width:70px; max-width: 70px;" >
|
||||
% if line == line_dict[0]:
|
||||
<b>
|
||||
${line.get("credit_ref") or ''}
|
||||
</b>
|
||||
% else:
|
||||
${line.get("credit_ref") or ''}
|
||||
% endif
|
||||
</td>
|
||||
<td style="border:1px solid #000000;width:150px; min-width:150px; max-width: 150px;" >
|
||||
% if line == line_dict[0]:
|
||||
<b>
|
||||
${line.get("supp_inv") or ''}
|
||||
</b>
|
||||
% else:
|
||||
${line.get("supp_inv") or ''}
|
||||
% endif
|
||||
</td>
|
||||
<td style="border:1px solid #000000;width:70px; min-width:70px; max-width: 70px;" >
|
||||
% if line == line_dict[0]:
|
||||
<b>
|
||||
${line.get("payment_amount") or ''}
|
||||
</b>
|
||||
% else:
|
||||
${'%.2f' % line.get("payment_amount") or ''}
|
||||
% endif
|
||||
</td>
|
||||
<td style="border:1px solid #000000;width:70px; min-width:70px; max-width: 70px;" >
|
||||
% if line == line_dict[0]:
|
||||
<b>
|
||||
${line.get("inv_amount") or ''}
|
||||
</b>
|
||||
% else:
|
||||
${'%.2f' %line.get("inv_amount") or ''}
|
||||
% endif
|
||||
</td>
|
||||
<td style="border:1px solid #000000;width:70px; min-width:70px; max-width: 70px;">
|
||||
% if line == line_dict[0]:
|
||||
<b>
|
||||
${line.get("credit_amount") or ''}
|
||||
</b>
|
||||
% else:
|
||||
${'%.2f' % line.get("credit_amount") or ''}
|
||||
% endif
|
||||
</td>
|
||||
<td style="border:1px solid #000000;width:70px; min-width:70px; max-width: 70px;">
|
||||
% if line == line_dict[0]:
|
||||
<b>
|
||||
${line.get("discount") or ''}
|
||||
</b>
|
||||
% else:
|
||||
${line.get("discount") or ''}
|
||||
% endif
|
||||
</td>
|
||||
<td style="border:1px solid #000000;width:70px; min-width:70px; max-width: 70px;">
|
||||
% if line == line_dict[0]:
|
||||
<b>
|
||||
${line.get("due_amount") or ''}
|
||||
</b>
|
||||
% else:
|
||||
${'%.2f' % line.get("due_amount") or ''}
|
||||
% endif
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
% endfor
|
||||
Thanks,
|
||||
% if user.signature:
|
||||
<br/>
|
||||
${user.signature | safe}
|
||||
% endif
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td style="text-align:center;">
|
||||
<hr
|
||||
width="100%"
|
||||
style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;"
|
||||
/>
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" style="min-width: 800px;">
|
||||
<table
|
||||
border="0"
|
||||
cellpadding="0"
|
||||
cellspacing="0"
|
||||
width="800"
|
||||
style="min-width: 800px; background-color: white; font-size: 11px; padding: 0px 8px 0px 8px; border-collapse:separate;"
|
||||
>
|
||||
<tr><td valign="middle" align="left">
|
||||
${object.company_id.name}
|
||||
</td></tr>
|
||||
<tr><td
|
||||
valign="middle"
|
||||
align="left"
|
||||
style="opacity: 0.7;"
|
||||
>
|
||||
${object.company_id.phone}
|
||||
% if object.company_id.email
|
||||
| <a
|
||||
href="'mailto:%s' % ${object.company_id.email}"
|
||||
style="text-decoration:none; color: #454748;"
|
||||
>
|
||||
${object.company_id.email}</a>
|
||||
% endif
|
||||
% if object.company_id.website
|
||||
| <a
|
||||
href="'%s' % ${object.company_id.website}"
|
||||
style="text-decoration:none; color: #454748;"
|
||||
>
|
||||
${object.company_id.website}
|
||||
</a>
|
||||
% endif
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<!-- POWERED BY -->
|
||||
<tr><td align="center" style="min-width: 800px;">
|
||||
<table
|
||||
border="0"
|
||||
cellpadding="0"
|
||||
cellspacing="0"
|
||||
width="800"
|
||||
style="min-width: 800px; background-color: white; color: #454748; padding: 8px; border-collapse:separate;"
|
||||
>
|
||||
<tr><td style="text-align: center; font-size: 13px;">
|
||||
Powered by <a
|
||||
target="_blank"
|
||||
href="https://www.odoo.com?utm_source=db&utm_medium=auth"
|
||||
style="color: #875A7B;"
|
||||
>Odoo</a>
|
||||
</td></tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
</table>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
1
account_payment_order_vendor_email/models/__init__.py
Normal file
1
account_payment_order_vendor_email/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import account_payment_mode
|
||||
@@ -0,0 +1,108 @@
|
||||
# Copyright (C) 2020 Open Source Integrators
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from odoo import _, fields, models
|
||||
|
||||
|
||||
class PaymentModeCustom(models.Model):
|
||||
_inherit = "account.payment.mode"
|
||||
|
||||
send_email_to_partner = fields.Boolean(
|
||||
string="Send Email to Partner", default=False
|
||||
)
|
||||
email_temp_id = fields.Many2one(
|
||||
"mail.template",
|
||||
string="Email Template",
|
||||
)
|
||||
|
||||
|
||||
class PaymentOrder(models.Model):
|
||||
_inherit = "account.payment.order"
|
||||
|
||||
def send_vendor_email(self):
|
||||
for rec in self:
|
||||
if rec.payment_mode_id.send_email_to_partner:
|
||||
date_generated = rec.date_generated
|
||||
for bank_line in rec.bank_line_ids:
|
||||
partner_name = bank_line.partner_id.name
|
||||
total_amount = bank_line.amount_currency
|
||||
payment_ref = bank_line.name
|
||||
line_data = []
|
||||
header_data = {
|
||||
"inv_no": "Invoice No.",
|
||||
"payment_amount": "Payment (in dollars)",
|
||||
"discount": "Discount (in dollars)",
|
||||
"inv_date": "Invoice Date",
|
||||
"credit_ref": "Credit ref#",
|
||||
"supp_inv": "Supp. Invoice#",
|
||||
"inv_amount": "Invoice Amount",
|
||||
"credit_amount": "Credit Amount",
|
||||
"due_amount": "Due Amount",
|
||||
}
|
||||
line_data.append(header_data)
|
||||
for payment_line in bank_line.payment_line_ids:
|
||||
invoice_date = (
|
||||
payment_line.move_line_id.move_id.invoice_date
|
||||
and datetime.strftime(
|
||||
payment_line.move_line_id.move_id.invoice_date,
|
||||
"%Y/%m/%d",
|
||||
)
|
||||
or ""
|
||||
)
|
||||
line_dict = {
|
||||
"inv_no": payment_line.move_line_id.move_id.name or "",
|
||||
"payment_amount": payment_line.amount_currency,
|
||||
"discount": payment_line.discount_amount,
|
||||
"inv_date": invoice_date or "",
|
||||
"credit_ref": payment_line.order_id.name,
|
||||
"supp_inv": payment_line.move_line_id.move_id.name or "",
|
||||
"inv_amount": payment_line.move_line_id.move_id.amount_total,
|
||||
"credit_amount": payment_line.move_line_id.move_id.amount_untaxed,
|
||||
"due_amount": payment_line.move_line_id.move_id.amount_residual,
|
||||
}
|
||||
line_data.append(line_dict)
|
||||
template = rec.payment_mode_id.email_temp_id
|
||||
if not template:
|
||||
template = self.env.ref(
|
||||
"account_payment_order_vendor_email."
|
||||
"ach_payment_email_template"
|
||||
)
|
||||
partner_email_id = bank_line.partner_id.email
|
||||
if partner_email_id:
|
||||
template.write({"email_to": partner_email_id})
|
||||
template.with_context(
|
||||
{
|
||||
"date": date_generated,
|
||||
"partner_name": partner_name,
|
||||
"total_amount": total_amount,
|
||||
"payment_ref": payment_ref,
|
||||
"line_data": line_data,
|
||||
}
|
||||
).send_mail(rec.id, force_send=True)
|
||||
rec.message_post(
|
||||
body=_(
|
||||
"An email is sent successfully to %s vendor."
|
||||
% partner_name
|
||||
)
|
||||
)
|
||||
else:
|
||||
rec.message_post(
|
||||
body=_(
|
||||
"An email is not able to send to %s vendor."
|
||||
% partner_name
|
||||
)
|
||||
)
|
||||
|
||||
def generated2uploaded(self):
|
||||
res = super(PaymentOrder, self).generated2uploaded()
|
||||
if self.payment_mode_id.send_email_to_partner:
|
||||
self.send_vendor_email()
|
||||
return res
|
||||
|
||||
|
||||
class AccountPaymentLine(models.Model):
|
||||
_inherit = "account.payment.line"
|
||||
|
||||
discount_amount = fields.Monetary(currency_field="currency_id")
|
||||
@@ -0,0 +1,4 @@
|
||||
* Murtaza Mithaiwala <mmithaiwala@opensourceintegrators.com>
|
||||
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
|
||||
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
|
||||
* Daniel Reis <dreis@opensourceintegrators.com>
|
||||
@@ -0,0 +1 @@
|
||||
Add fields to Account Payment Mode.
|
||||
5
account_payment_order_vendor_email/readme/USAGE.rst
Normal file
5
account_payment_order_vendor_email/readme/USAGE.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
Add `send_email_to_partner` on Account Payment Mode records.
|
||||
|
||||
Add 'email_temp_id' on Account Payment Mode records.
|
||||
|
||||
Add Email templated to send the Payment Details on Mail
|
||||
BIN
account_payment_order_vendor_email/static/description/icon.png
Normal file
BIN
account_payment_order_vendor_email/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
4
account_payment_order_vendor_email/tests/__init__.py
Normal file
4
account_payment_order_vendor_email/tests/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# Copyright (C) 2021 Open Source Integrators
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import test_account_payment_order_vendor_mail
|
||||
@@ -0,0 +1,66 @@
|
||||
# Copyright (C) 2021 Open Source Integrators
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestVendorEmail(TransactionCase):
|
||||
def setUp(self):
|
||||
super(TestVendorEmail, self).setUp()
|
||||
|
||||
# Company
|
||||
self.company = self.env.ref("base.main_company")
|
||||
|
||||
self.journal_c1 = self.env["account.journal"].create(
|
||||
{
|
||||
"name": "Journal 1",
|
||||
"code": "J1",
|
||||
"type": "bank",
|
||||
"company_id": self.company.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.manual_out = self.env.ref("account.account_payment_method_manual_out")
|
||||
|
||||
self.email_template = self.env.ref(
|
||||
"account_payment_order_vendor_email.ach_payment_email_template"
|
||||
)
|
||||
|
||||
self.partner_id = self.env.ref("base.res_partner_12")
|
||||
|
||||
self.payment_mode_c1 = self.env["account.payment.mode"].create(
|
||||
{
|
||||
"name": "Direct Debit of suppliers from Bank 1",
|
||||
"bank_account_link": "variable",
|
||||
"payment_method_id": self.manual_out.id,
|
||||
"company_id": self.company.id,
|
||||
"fixed_journal_id": self.journal_c1.id,
|
||||
"variable_journal_ids": [(6, 0, [self.journal_c1.id])],
|
||||
"send_email_to_partner": True,
|
||||
"email_temp_id": self.email_template.id,
|
||||
}
|
||||
)
|
||||
|
||||
def test_send_vendor_email(self):
|
||||
self.payment_order_id = self.env["account.payment.order"].create(
|
||||
{
|
||||
"payment_mode_id": self.payment_mode_c1.id,
|
||||
"journal_id": self.journal_c1.id,
|
||||
"payment_type": "outbound",
|
||||
"payment_line_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"amount_currency": 200.00,
|
||||
"partner_id": self.partner_id.id,
|
||||
"communication": "TEST",
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
self.payment_order_id.draft2open()
|
||||
self.payment_order_id.open2generated()
|
||||
self.payment_order_id.generated2uploaded()
|
||||
self.payment_order_id.send_vendor_email()
|
||||
@@ -0,0 +1,16 @@
|
||||
<odoo>
|
||||
<record id="account_payment_mode_inherit_email" model="ir.ui.view">
|
||||
<field name="name">account_payment_mode_email_inherit</field>
|
||||
<field name="model">account.payment.mode</field>
|
||||
<field name="inherit_id" ref="account_payment_mode.account_payment_mode_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="variable_journal_ids" position="after">
|
||||
<field name="send_email_to_partner" />
|
||||
<field
|
||||
attrs="{'invisible':[('send_email_to_partner','=',False)],'required':[('send_email_to_partner','=',True)]}"
|
||||
name="email_temp_id"
|
||||
/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -0,0 +1,21 @@
|
||||
<odoo>
|
||||
<record id="account_payment_order_manual_email_form" model="ir.ui.view">
|
||||
<field name="name">account_payment_order_manual_email_form</field>
|
||||
<field name="model">account.payment.order</field>
|
||||
<field
|
||||
name="inherit_id"
|
||||
ref="account_payment_order.account_payment_order_form"
|
||||
/>
|
||||
<field name="arch" type="xml">
|
||||
<button name="action_uploaded_cancel" position="after">
|
||||
<button
|
||||
name="send_vendor_email"
|
||||
string="Send Email"
|
||||
type="object"
|
||||
class="oe_highlight"
|
||||
states="uploaded"
|
||||
/>
|
||||
</button>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user