-
-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[14.0][ADD] account_invoice_qr_code_sepa_payconiq
- Loading branch information
1 parent
325d652
commit 7753973
Showing
20 changed files
with
926 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
===================================== | ||
Account Invoice Qr Code Sepa Payconiq | ||
===================================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! 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%2Faccount--invoicing-lightgray.png?logo=github | ||
:target: https://github.com/OCA/account-invoicing/tree/14.0/account_invoice_qr_code_sepa_payconiq | ||
:alt: OCA/account-invoicing | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/account-invoicing-14-0/account-invoicing-14-0-account_invoice_qr_code_sepa_payconiq | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/95/14.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to generate a QR code to be displayed on invoices. | ||
|
||
This differs from the SEPA QR Code as Payconiq in some countries (e.g.: LU) | ||
requires invoices emitters to pay a fee per paid transactions through this mean. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
#. Go to Accounting > Settings > Customer Payments > QR Codes | ||
|
||
Fill in the Payconiq Profile Id you've been given. | ||
|
||
Usage | ||
===== | ||
|
||
See Odoo documentation for SEPA QR code. | ||
|
||
https://www.odoo.com/documentation/master/applications/finance/accounting/receivables/customer_invoices/epc_qr_code.html | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
* At the time being, this is only available in Luxembourg. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-invoicing/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 <https://github.com/OCA/account-invoicing/issues/new?body=module:%20account_invoice_qr_code_sepa_payconiq%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* ACSONE SA/NV | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Denis Roussel <[email protected]> | ||
|
||
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/account-invoicing <https://github.com/OCA/account-invoicing/tree/14.0/account_invoice_qr_code_sepa_payconiq>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2022 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Account Invoice Qr Code Sepa Payconiq", | ||
"summary": """ | ||
Allows to generate a qr code for Payconiq provider containing the url""", | ||
"version": "14.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "ACSONE SA/NV,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/account-invoicing", | ||
"depends": [ | ||
"account_qr_code_sepa", | ||
], | ||
"data": [ | ||
"views/res_config_settings.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import res_company, res_config_settings, res_partner_bank |
13 changes: 13 additions & 0 deletions
13
account_invoice_qr_code_sepa_payconiq/models/res_company.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2022 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
|
||
_inherit = "res.company" | ||
|
||
payconiq_qr_profile_id = fields.Char( | ||
string="Payconiq Profile Id", help="Fill in this with your payment profile Id" | ||
) |
12 changes: 12 additions & 0 deletions
12
account_invoice_qr_code_sepa_payconiq/models/res_config_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2022 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
payconiq_qr_profile_id = fields.Char( | ||
related="company_id.payconiq_qr_profile_id", | ||
readonly=False, | ||
) |
178 changes: 178 additions & 0 deletions
178
account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
# Copyright 2022 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
import base64 | ||
import io | ||
import urllib | ||
|
||
import requests | ||
from PIL import Image | ||
|
||
from odoo import _, api, models | ||
from odoo.tools.image import image_data_uri | ||
|
||
PAYCONIQ_URL = "https://payconiq.com/t/1/" | ||
PAYCONIQ_QR_URL = "https://portal.payconiq.com/qrcode" | ||
|
||
|
||
class ResPartnerBank(models.Model): | ||
|
||
_inherit = "res.partner.bank" | ||
|
||
@api.model | ||
def _get_available_qr_methods(self): | ||
rslt = super()._get_available_qr_methods() | ||
rslt.append(("payconiq_qr", _("Payconiq QR"), 19)) | ||
return rslt | ||
|
||
def _get_payconiq_qr_amount(self, amount): | ||
""" | ||
Payconiq is awaiting an amount in eurocents. So, | ||
if the amount is for instance 141.9, reformat to float with | ||
two decimals => 141.90, then remove decimal dot. | ||
""" | ||
return "{amount:.2f}".format(amount=amount).replace(".", "") | ||
|
||
def _get_qr_code_generation_params( | ||
self, | ||
qr_method, | ||
amount, | ||
currency, | ||
debtor_partner, | ||
free_communication, | ||
structured_communication, | ||
): | ||
""" | ||
https://developer.payconiq.com/online-payments-dock/#creating-the-payconiq-qr-code77 | ||
""" | ||
if qr_method == "payconiq_qr": | ||
return { | ||
"payconiq_qr": True, | ||
"D": "Payment", | ||
"A": self._get_payconiq_qr_amount(amount), | ||
"R": structured_communication | ||
if structured_communication | ||
else free_communication, | ||
} | ||
return super()._get_qr_code_generation_params( | ||
qr_method, | ||
amount, | ||
currency, | ||
debtor_partner, | ||
free_communication, | ||
structured_communication, | ||
) | ||
|
||
def _get_qr_code_url( | ||
self, | ||
qr_method, | ||
amount, | ||
currency, | ||
debtor_partner, | ||
free_communication, | ||
structured_communication, | ||
): | ||
params = self._get_qr_code_generation_params( | ||
qr_method, | ||
amount, | ||
currency, | ||
debtor_partner, | ||
free_communication, | ||
structured_communication, | ||
) | ||
if params and params.get("payconiq", False): | ||
params.pops("payconiq_qr") | ||
return urllib.parse.urlencode(params) | ||
return super()._get_qr_code_url( | ||
qr_method, | ||
amount, | ||
currency, | ||
debtor_partner, | ||
free_communication, | ||
structured_communication, | ||
) | ||
|
||
def _eligible_for_qr_code(self, qr_method, debtor_partner, currency): | ||
if qr_method == "payconiq_qr": | ||
return ( | ||
currency.name == "EUR" | ||
and self.acc_type == "iban" | ||
and self.sanitized_acc_number[:2] in ["LU"] | ||
) | ||
return super()._eligible_for_qr_code(qr_method, debtor_partner, currency) | ||
|
||
def _get_qr_code_base64( | ||
self, | ||
qr_method, | ||
amount, | ||
currency, | ||
debtor_partner, | ||
free_communication, | ||
structured_communication, | ||
): | ||
""" | ||
The url to get QR code image from Payconiq is composed by several parameters: | ||
- The type of the image | ||
- The image size | ||
- The redirection url (to launch the payconiq application - this is the url | ||
inside the QR code itself) | ||
""" | ||
params = self._get_qr_code_generation_params( | ||
qr_method, | ||
amount, | ||
currency, | ||
debtor_partner, | ||
free_communication, | ||
structured_communication, | ||
) | ||
if params and params.get("payconiq_qr", False): | ||
params.pop("payconiq_qr") | ||
profile_id = self.env.company.payconiq_qr_profile_id | ||
# Build url that would be contained in QR code | ||
c_url = PAYCONIQ_URL + profile_id + "?" | ||
new_params = { | ||
"f": "PNG", | ||
"s": "S", | ||
"c": c_url + urllib.parse.urlencode(params), | ||
} | ||
response = requests.get(PAYCONIQ_QR_URL, params=new_params, stream=True) | ||
raw_image = response.raw | ||
img = Image.open(raw_image) | ||
|
||
buffer = io.BytesIO() | ||
img.save(buffer, format="PNG") | ||
myimage = buffer.getvalue() | ||
barcode = image_data_uri(base64.b64encode(myimage)) | ||
return barcode | ||
return super()._get_qr_code_base64( | ||
qr_method, | ||
amount, | ||
currency, | ||
debtor_partner, | ||
free_communication, | ||
structured_communication, | ||
) | ||
|
||
def _check_for_qr_code_errors( | ||
self, | ||
qr_method, | ||
amount, | ||
currency, | ||
debtor_partner, | ||
free_communication, | ||
structured_communication, | ||
): | ||
if qr_method == "payconiq_qr": | ||
if not self.env.company.payconiq_qr_profile_id: | ||
return _( | ||
"You should provide a Payconiq Profile Id (Accounting > Settings > " | ||
"Customer Payments > QR Codes" | ||
) | ||
return super()._check_for_qr_code_errors( | ||
qr_method, | ||
amount, | ||
currency, | ||
debtor_partner, | ||
free_communication, | ||
structured_communication, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#. Go to Accounting > Settings > Customer Payments > QR Codes | ||
|
||
Fill in the Payconiq Profile Id you've been given. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Denis Roussel <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This module allows to generate a QR code to be displayed on invoices. | ||
|
||
This differs from the SEPA QR Code as Payconiq in some countries (e.g.: LU) | ||
requires invoices emitters to pay a fee per paid transactions through this mean. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* At the time being, this is only available in Luxembourg. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
See Odoo documentation for SEPA QR code. | ||
|
||
https://www.odoo.com/documentation/master/applications/finance/accounting/receivables/customer_invoices/epc_qr_code.html |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.