diff --git a/account_payment_order_vendor_email/README.rst b/account_payment_order_vendor_email/README.rst new file mode 100644 index 000000000..10d06c936 --- /dev/null +++ b/account_payment_order_vendor_email/README.rst @@ -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 +* Maxime Chambreuil +* Serpent Consulting Services Pvt. Ltd. + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_payment_order_vendor_email/__init__.py b/account_payment_order_vendor_email/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_payment_order_vendor_email/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_payment_order_vendor_email/__manifest__.py b/account_payment_order_vendor_email/__manifest__.py new file mode 100644 index 000000000..5050dc4bf --- /dev/null +++ b/account_payment_order_vendor_email/__manifest__.py @@ -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, +} diff --git a/account_payment_order_vendor_email/data/mail_template.xml b/account_payment_order_vendor_email/data/mail_template.xml new file mode 100644 index 000000000..1bff0e5fb --- /dev/null +++ b/account_payment_order_vendor_email/data/mail_template.xml @@ -0,0 +1,252 @@ + + + + + Email for ACH Payments + + ${object.company_id.name | safe} <${(object.company_id.email or user.email) | safe}> + + Remittance Advice + + ${object.generated_user_id.lang} + + +
+ + + + + + + + +
+ Remittance + Advice
+ + ${object.name} + +
+ ${object.company_id.name} +
+
+
+ + + + + + + + +
+
+ Dear ${object.name},

+ A payment was processed on ${ctx['date']} + for ${ctx['partner_name']} in the amount of + ${ctx['total_amount']} with reference + ${ctx['payment_ref']}.

+ % set line_dict = ctx.get('line_data',False) + % for line in line_dict: + + + + + + + + + + + + +
+ % if line == line_dict[0]: + + ${line.get("inv_date") or ''} + + % else: + ${line.get("inv_date") or ''} + % endif + + % if line == line_dict[0]: + + ${line.get("inv_no") or ''} + + % else: + ${line.get("inv_no") or ''} + % endif + + % if line == line_dict[0]: + + ${line.get("credit_ref") or ''} + + % else: + ${line.get("credit_ref") or ''} + % endif + + % if line == line_dict[0]: + + ${line.get("supp_inv") or ''} + + % else: + ${line.get("supp_inv") or ''} + % endif + + % if line == line_dict[0]: + + ${line.get("payment_amount") or ''} + + % else: + ${'%.2f' % line.get("payment_amount") or ''} + % endif + + % if line == line_dict[0]: + + ${line.get("inv_amount") or ''} + + % else: + ${'%.2f' %line.get("inv_amount") or ''} + % endif + + % if line == line_dict[0]: + + ${line.get("credit_amount") or ''} + + % else: + ${'%.2f' % line.get("credit_amount") or ''} + % endif + + % if line == line_dict[0]: + + ${line.get("discount") or ''} + + % else: + ${line.get("discount") or ''} + % endif + + % if line == line_dict[0]: + + ${line.get("due_amount") or ''} + + % else: + ${'%.2f' % line.get("due_amount") or ''} + % endif +
+ % endfor + Thanks, + % if user.signature: +
+ ${user.signature | safe} + % endif +
+
+
+
+ + + + + + + +
+ ${object.company_id.name} +
+ ${object.company_id.phone} + % if object.company_id.email + | + ${object.company_id.email} + % endif + % if object.company_id.website + | + ${object.company_id.website} + + % endif +
+ + + + + + + +
+ Powered by Odoo +
+ + + ]]> +
+
+ +
diff --git a/account_payment_order_vendor_email/models/__init__.py b/account_payment_order_vendor_email/models/__init__.py new file mode 100644 index 000000000..715a4994f --- /dev/null +++ b/account_payment_order_vendor_email/models/__init__.py @@ -0,0 +1 @@ +from . import account_payment_mode diff --git a/account_payment_order_vendor_email/models/account_payment_mode.py b/account_payment_order_vendor_email/models/account_payment_mode.py new file mode 100644 index 000000000..3ae72e287 --- /dev/null +++ b/account_payment_order_vendor_email/models/account_payment_mode.py @@ -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") diff --git a/account_payment_order_vendor_email/readme/CONTRIBUTORS.rst b/account_payment_order_vendor_email/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..a230e9130 --- /dev/null +++ b/account_payment_order_vendor_email/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Murtaza Mithaiwala +* Maxime Chambreuil +* Serpent Consulting Services Pvt. Ltd. +* Daniel Reis diff --git a/account_payment_order_vendor_email/readme/DESCRIPTION.rst b/account_payment_order_vendor_email/readme/DESCRIPTION.rst new file mode 100644 index 000000000..7107f7077 --- /dev/null +++ b/account_payment_order_vendor_email/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Add fields to Account Payment Mode. diff --git a/account_payment_order_vendor_email/readme/USAGE.rst b/account_payment_order_vendor_email/readme/USAGE.rst new file mode 100644 index 000000000..6c9203dab --- /dev/null +++ b/account_payment_order_vendor_email/readme/USAGE.rst @@ -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 diff --git a/account_payment_order_vendor_email/static/description/icon.png b/account_payment_order_vendor_email/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_payment_order_vendor_email/static/description/icon.png differ diff --git a/account_payment_order_vendor_email/tests/__init__.py b/account_payment_order_vendor_email/tests/__init__.py new file mode 100644 index 000000000..587b33984 --- /dev/null +++ b/account_payment_order_vendor_email/tests/__init__.py @@ -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 diff --git a/account_payment_order_vendor_email/tests/test_account_payment_order_vendor_mail.py b/account_payment_order_vendor_email/tests/test_account_payment_order_vendor_mail.py new file mode 100644 index 000000000..87983e30d --- /dev/null +++ b/account_payment_order_vendor_email/tests/test_account_payment_order_vendor_mail.py @@ -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() diff --git a/account_payment_order_vendor_email/views/account_payment_mode_view.xml b/account_payment_order_vendor_email/views/account_payment_mode_view.xml new file mode 100644 index 000000000..5dbbd1bf7 --- /dev/null +++ b/account_payment_order_vendor_email/views/account_payment_mode_view.xml @@ -0,0 +1,16 @@ + + + account_payment_mode_email_inherit + account.payment.mode + + + + + + + + + diff --git a/account_payment_order_vendor_email/views/account_payment_order_view.xml b/account_payment_order_vendor_email/views/account_payment_order_view.xml new file mode 100644 index 000000000..3634b1bf0 --- /dev/null +++ b/account_payment_order_vendor_email/views/account_payment_order_view.xml @@ -0,0 +1,21 @@ + + + account_payment_order_manual_email_form + account.payment.order + + + + + + diff --git a/setup/account_payment_order_vendor_email/odoo/addons/account_payment_order_vendor_email b/setup/account_payment_order_vendor_email/odoo/addons/account_payment_order_vendor_email new file mode 120000 index 000000000..2b15336c2 --- /dev/null +++ b/setup/account_payment_order_vendor_email/odoo/addons/account_payment_order_vendor_email @@ -0,0 +1 @@ +../../../../account_payment_order_vendor_email \ No newline at end of file diff --git a/setup/account_payment_order_vendor_email/setup.py b/setup/account_payment_order_vendor_email/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_payment_order_vendor_email/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)