From 0f55e6a773a1a4a323864d17d494fc876d03384e Mon Sep 17 00:00:00 2001 From: "Nishant Jain (niai)" Date: Wed, 4 Jan 2023 13:31:37 +0000 Subject: [PATCH] [ADD] l10n_in_upi: added qr code for upi payment in invoice report Currently, there is no facility for UPI payment for the invoice. So in this commit, there will be a QR code for UPI payment in the invoice report. closes odoo/odoo#109237 X-original-commit: e8e75678ee64fd9e4150ab7c9a9836d69b06c4db Signed-off-by: Quentin De Paoli Signed-off-by: Jigar Vaghela (jva) --- addons/l10n_in_upi/__init__.py | 3 +++ addons/l10n_in_upi/__manifest__.py | 18 +++++++++++++++ addons/l10n_in_upi/models/__init__.py | 4 ++++ addons/l10n_in_upi/models/account_invoice.py | 23 +++++++++++++++++++ addons/l10n_in_upi/models/res_company.py | 10 ++++++++ .../l10n_in_upi/views/res_company_views.xml | 13 +++++++++++ 6 files changed, 71 insertions(+) create mode 100644 addons/l10n_in_upi/__init__.py create mode 100644 addons/l10n_in_upi/__manifest__.py create mode 100644 addons/l10n_in_upi/models/__init__.py create mode 100644 addons/l10n_in_upi/models/account_invoice.py create mode 100644 addons/l10n_in_upi/models/res_company.py create mode 100644 addons/l10n_in_upi/views/res_company_views.xml diff --git a/addons/l10n_in_upi/__init__.py b/addons/l10n_in_upi/__init__.py new file mode 100644 index 00000000000..be9f4fab00a --- /dev/null +++ b/addons/l10n_in_upi/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import models diff --git a/addons/l10n_in_upi/__manifest__.py b/addons/l10n_in_upi/__manifest__.py new file mode 100644 index 00000000000..7c6d6ec73ae --- /dev/null +++ b/addons/l10n_in_upi/__manifest__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +{ + 'name': 'Indian - UPI', + 'version': '1.0', + 'description': """ +Invoice with UPI QR code +========================= +This module adds QR code in invoice report for UPI payment allowing to make payment via any UPI app. + +To print UPI Qr code add UPI id in company and tick "QR Codes" in configuration + """, + 'category': 'Accounting/Localizations', + 'depends': ['l10n_in'], + 'data': ['views/res_company_views.xml'], + 'license': 'LGPL-3', + 'auto_install': True, +} diff --git a/addons/l10n_in_upi/models/__init__.py b/addons/l10n_in_upi/models/__init__.py new file mode 100644 index 00000000000..1bd4ba68797 --- /dev/null +++ b/addons/l10n_in_upi/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding:utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import account_invoice +from . import res_company diff --git a/addons/l10n_in_upi/models/account_invoice.py b/addons/l10n_in_upi/models/account_invoice.py new file mode 100644 index 00000000000..d7ffab93a17 --- /dev/null +++ b/addons/l10n_in_upi/models/account_invoice.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +import base64 + +from odoo import models +from odoo.tools.image import image_data_uri + + +class AccountMove(models.Model): + _inherit = "account.move" + + def generate_qr_code(self): + self.ensure_one() + if self.company_id.country_code == 'IN': + payment_url = 'upi://pay?pa=%s&pn=%s&am=%s&tr=%s&tn=%s' % ( + self.company_id.l10n_in_upi_id, + self.company_id.name, + self.amount_residual, + self.payment_reference or self.name, + ("Payment for %s" % self.name)) + barcode = self.env['ir.actions.report'].barcode(barcode_type="QR", value=payment_url, width=120, height=120) + return image_data_uri(base64.b64encode(barcode)) + return super().generate_qr_code() diff --git a/addons/l10n_in_upi/models/res_company.py b/addons/l10n_in_upi/models/res_company.py new file mode 100644 index 00000000000..9adfe1f1ed8 --- /dev/null +++ b/addons/l10n_in_upi/models/res_company.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class Company(models.Model): + _inherit = 'res.company' + + l10n_in_upi_id = fields.Char(string="UPI Id") diff --git a/addons/l10n_in_upi/views/res_company_views.xml b/addons/l10n_in_upi/views/res_company_views.xml new file mode 100644 index 00000000000..3a317fb47b1 --- /dev/null +++ b/addons/l10n_in_upi/views/res_company_views.xml @@ -0,0 +1,13 @@ + + + + res.company.form.inherit.l10n_in_upi + res.company + + + + + + + +