Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD] account_invoice_qr_code_sepa_payconiq #1248

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions account_invoice_qr_code_sepa_payconiq/README.rst
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.
1 change: 1 addition & 0 deletions account_invoice_qr_code_sepa_payconiq/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions account_invoice_qr_code_sepa_payconiq/__manifest__.py
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",
],
}
1 change: 1 addition & 0 deletions account_invoice_qr_code_sepa_payconiq/models/__init__.py
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 account_invoice_qr_code_sepa_payconiq/models/res_company.py
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"
)
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,
)
177 changes: 177 additions & 0 deletions account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# 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 f"{amount*100:.0f}"

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(

Check warning on line 57 in account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py#L57

Added line #L57 was not covered by tests
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(

Check warning on line 75 in account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py#L75

Added line #L75 was not covered by tests
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(

Check warning on line 86 in account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py#L84-L86

Added lines #L84 - L86 were not covered by tests
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"]
adrienpeiffer marked this conversation as resolved.
Show resolved Hide resolved
)
return super()._eligible_for_qr_code(qr_method, debtor_partner, currency)

Check warning on line 102 in account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py#L102

Added line #L102 was not covered by tests

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.pop("payconiq_qr", False):
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(

Check warning on line 146 in account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py#L146

Added line #L146 was not covered by tests
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 _(

Check warning on line 166 in account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_qr_code_sepa_payconiq/models/res_partner_bank.py#L166

Added line #L166 was not covered by tests
"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,
)
3 changes: 3 additions & 0 deletions account_invoice_qr_code_sepa_payconiq/readme/CONFIGURE.rst
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Denis Roussel <[email protected]>
4 changes: 4 additions & 0 deletions account_invoice_qr_code_sepa_payconiq/readme/DESCRIPTION.rst
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.
1 change: 1 addition & 0 deletions account_invoice_qr_code_sepa_payconiq/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* At the time being, this is only available in Luxembourg.
3 changes: 3 additions & 0 deletions account_invoice_qr_code_sepa_payconiq/readme/USAGE.rst
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.
Loading
Loading