diff --git a/account_payment_order_vendor_email/README.rst b/account_payment_order_vendor_email/README.rst new file mode 100644 index 000000000..d334937fa --- /dev/null +++ b/account_payment_order_vendor_email/README.rst @@ -0,0 +1,85 @@ +=========================== +Account Payment Order Email +=========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github + :target: https://github.com/OCA/bank-payment/tree/14.0/account_payment_order_vendor_email + :alt: OCA/bank-payment +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/bank-payment-14-0/bank-payment-14-0-account_payment_order_vendor_email + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/173/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +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 +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Open Source Integrators + +Contributors +~~~~~~~~~~~~ + +* Murtaza Mithaiwala +* Maxime Chambreuil +* Serpent Consulting Services Pvt. Ltd. +* Daniel Reis + +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/bank-payment `_ 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..5380cd3e1 --- /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": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "maintainers": ["ursais"], + "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..e679e9aa3 --- /dev/null +++ b/account_payment_order_vendor_email/data/mail_template.xml @@ -0,0 +1,350 @@ + + + + + Email for ACH Payments + + {{ object.company_id.email or user.email }} + + Remittance Advice + + {{ object.generated_user_id.lang }} + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + + + + + + +
+ Remittance + Advice + +
+ + + +
+ ${object.company_id.name} +
+
+
+
+ + + + + + + +
+
+ Dear , +

+ A payment was processed on + for in the amount of + with reference + .

+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ Thanks, + +
+ + +
+
+
+
+
+ + + + + + + +
+ +
+ + + | + + + + | + + +
+
+ + + + +
+ Powered by + Odoo +
+
+
+
+ +
diff --git a/account_payment_order_vendor_email/i18n/account_payment_order_vendor_email.pot b/account_payment_order_vendor_email/i18n/account_payment_order_vendor_email.pot new file mode 100644 index 000000000..3fbea9850 --- /dev/null +++ b/account_payment_order_vendor_email/i18n/account_payment_order_vendor_email.pot @@ -0,0 +1,323 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_order_vendor_email +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_payment_order_vendor_email +#: model:mail.template,body_html:account_payment_order_vendor_email.ach_payment_email_template +msgid "" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" Remittance\n" +" Advice
\n" +" \n" +" ${object.name}\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"
\n" +" Dear ${object.name},

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

\n" +" % set line_dict = ctx.get('line_data',False)\n" +" % for line in line_dict:\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"
\n" +" % if line == line_dict[0]:\n" +" \n" +" ${line.get(\"inv_date\") or ''}\n" +" \n" +" % else:\n" +" ${line.get(\"inv_date\") or ''}\n" +" % endif\n" +" \n" +" % if line == line_dict[0]:\n" +" \n" +" ${line.get(\"inv_no\") or ''}\n" +" \n" +" % else:\n" +" ${line.get(\"inv_no\") or ''}\n" +" % endif\n" +" \n" +" % if line == line_dict[0]:\n" +" \n" +" ${line.get(\"credit_ref\") or ''}\n" +" \n" +" % else:\n" +" ${line.get(\"credit_ref\") or ''}\n" +" % endif\n" +" \n" +" % if line == line_dict[0]:\n" +" \n" +" ${line.get(\"supp_inv\") or ''}\n" +" \n" +" % else:\n" +" ${line.get(\"supp_inv\") or ''}\n" +" % endif\n" +" \n" +" % if line == line_dict[0]:\n" +" \n" +" ${line.get(\"payment_amount\") or ''}\n" +" \n" +" % else:\n" +" ${'%.2f' % line.get(\"payment_amount\") or ''}\n" +" % endif\n" +" \n" +" % if line == line_dict[0]:\n" +" \n" +" ${line.get(\"inv_amount\") or ''}\n" +" \n" +" % else:\n" +" ${'%.2f' %line.get(\"inv_amount\") or ''}\n" +" % endif\n" +" \n" +" % if line == line_dict[0]:\n" +" \n" +" ${line.get(\"credit_amount\") or ''}\n" +" \n" +" % else:\n" +" ${'%.2f' % line.get(\"credit_amount\") or ''}\n" +" % endif\n" +" \n" +" % if line == line_dict[0]:\n" +" \n" +" ${line.get(\"discount\") or ''}\n" +" \n" +" % else:\n" +" ${line.get(\"discount\") or ''}\n" +" % endif\n" +" \n" +" % if line == line_dict[0]:\n" +" \n" +" ${line.get(\"due_amount\") or ''}\n" +" \n" +" % else:\n" +" ${'%.2f' % line.get(\"due_amount\") or ''}\n" +" % endif\n" +"
\n" +" % endfor\n" +" Thanks,\n" +" % if user.signature:\n" +"
\n" +" ${user.signature | safe}\n" +" % endif\n" +"
\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" ${object.company_id.name}\n" +" \n" +" \n" +" ${object.company_id.phone}\n" +" % if object.company_id.email\n" +" | \n" +" ${object.company_id.email}\n" +" % endif\n" +" % if object.company_id.website\n" +" | \n" +" ${object.company_id.website}\n" +" \n" +" % endif\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" Powered by Odoo\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" " +msgstr "" + +#. module: account_payment_order_vendor_email +#: code:addons/account_payment_order_vendor_email/models/account_payment_mode.py:0 +#, python-format +msgid "An email is not able to send to %s vendor." +msgstr "" + +#. module: account_payment_order_vendor_email +#: code:addons/account_payment_order_vendor_email/models/account_payment_mode.py:0 +#, python-format +msgid "An email is sent successfully to %s vendor." +msgstr "" + +#. module: account_payment_order_vendor_email +#: model:ir.model.fields,field_description:account_payment_order_vendor_email.field_account_payment_line__discount_amount +msgid "Discount Amount" +msgstr "" + +#. module: account_payment_order_vendor_email +#: model:ir.model.fields,field_description:account_payment_order_vendor_email.field_account_payment_line__display_name +#: model:ir.model.fields,field_description:account_payment_order_vendor_email.field_account_payment_mode__display_name +#: model:ir.model.fields,field_description:account_payment_order_vendor_email.field_account_payment_order__display_name +msgid "Display Name" +msgstr "" + +#. module: account_payment_order_vendor_email +#: model:ir.model.fields,field_description:account_payment_order_vendor_email.field_account_payment_mode__email_temp_id +msgid "Email Template" +msgstr "" + +#. module: account_payment_order_vendor_email +#: model:ir.model.fields,field_description:account_payment_order_vendor_email.field_account_payment_line__id +#: model:ir.model.fields,field_description:account_payment_order_vendor_email.field_account_payment_mode__id +#: model:ir.model.fields,field_description:account_payment_order_vendor_email.field_account_payment_order__id +msgid "ID" +msgstr "" + +#. module: account_payment_order_vendor_email +#: model:ir.model.fields,field_description:account_payment_order_vendor_email.field_account_payment_line____last_update +#: model:ir.model.fields,field_description:account_payment_order_vendor_email.field_account_payment_mode____last_update +#: model:ir.model.fields,field_description:account_payment_order_vendor_email.field_account_payment_order____last_update +msgid "Last Modified on" +msgstr "" + +#. module: account_payment_order_vendor_email +#: model:ir.model,name:account_payment_order_vendor_email.model_account_payment_line +msgid "Payment Lines" +msgstr "" + +#. module: account_payment_order_vendor_email +#: model:ir.model,name:account_payment_order_vendor_email.model_account_payment_mode +msgid "Payment Modes" +msgstr "" + +#. module: account_payment_order_vendor_email +#: model:ir.model,name:account_payment_order_vendor_email.model_account_payment_order +msgid "Payment Order" +msgstr "" + +#. module: account_payment_order_vendor_email +#: model:mail.template,subject:account_payment_order_vendor_email.ach_payment_email_template +msgid "Remittance Advice" +msgstr "" + +#. module: account_payment_order_vendor_email +#: model_terms:ir.ui.view,arch_db:account_payment_order_vendor_email.account_payment_order_manual_email_form +msgid "Send Email" +msgstr "" + +#. module: account_payment_order_vendor_email +#: model:ir.model.fields,field_description:account_payment_order_vendor_email.field_account_payment_mode__send_email_to_partner +msgid "Send Email to Partner" +msgstr "" 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..7a65856aa --- /dev/null +++ b/account_payment_order_vendor_email/models/account_payment_mode.py @@ -0,0 +1,109 @@ +# Copyright (C) 2020 Open Source Integrators +# Copyright 2022 Tecnativa - Pedro M. Baeza +# 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): + context = dict(self._context) + for rec in self: + if rec.payment_mode_id.send_email_to_partner: + date_generated = rec.date_generated + for payment in rec.payment_ids: + partner_name = payment.partner_id.name + total_amount = payment.amount + payment_ref = payment.payment_reference + 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 payment.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 = payment.partner_id.email + if partner_email_id: + template.write({"email_to": partner_email_id}) + context.update( + { + "date": date_generated, + "partner_name": partner_name, + "total_amount": total_amount, + "payment_ref": payment_ref, + "line_data": line_data, + } + ) + template.with_context(**context).send_mail( + rec.id, force_send=True + ) + rec.message_post( + body=_("An email is not able to send 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..3741acc6c --- /dev/null +++ b/account_payment_order_vendor_email/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* Murtaza Mithaiwala +* Maxime Chambreuil +* Serpent Consulting Services Pvt. Ltd. +* Daniel Reis +* Nikul Chaudhary 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/static/description/index.html b/account_payment_order_vendor_email/static/description/index.html new file mode 100644 index 000000000..57cafca3d --- /dev/null +++ b/account_payment_order_vendor_email/static/description/index.html @@ -0,0 +1,429 @@ + + + + + + +Account Payment Order Email + + + +
+

Account Payment Order Email

+ + +

Beta License: AGPL-3 OCA/bank-payment Translate me on Weblate Try me on Runbot

+

Add fields to Account Payment Mode.

+

Table of contents

+ +
+

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

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Open Source Integrators
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/bank-payment 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/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, +)