-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stéphan Sainléger
committed
Mar 6, 2024
1 parent
ad413f3
commit 8eb7de8
Showing
7 changed files
with
189 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,65 @@ | ||
============= | ||
lcc_wallet_qr | ||
============= | ||
|
||
Module to generate a QR code containing the wallet information | ||
It's part of Lokavaluto Project (https://lokavaluto.fr) | ||
|
||
Installation | ||
============ | ||
|
||
Just install lcc_wallet_qr, all dependencies will be installed by default. | ||
|
||
Configuration | ||
============= | ||
|
||
No configuration needed on this addon. | ||
|
||
Usage | ||
===== | ||
|
||
To generate the QR code of a wallet, go on the form view of the wallet, anc click on the button "Generate QR". | ||
You will be able to download a pdf page containing the QR code, and you will find the PNG image in the "QR code" notebook page. | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/Lokavaluto/lokavaluto-addons/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. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Lokavaluto: `Icon <https://lokavaluto.fr/web/image/res.company/1/logo?unique=f3db262>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Stéphan SAINLEGER <https://github.com/stephansainleger> | ||
* Nicolas JEUDY <https://github.com/njeudy> | ||
* Lokavaluto Teams | ||
|
||
Funders | ||
------- | ||
|
||
The development of this module has been financially supported by: | ||
|
||
* Lokavaluto (https://lokavaluto.fr) | ||
* Mycéliandre (https://myceliandre.fr) | ||
* Elabore (https://elabore.coop) | ||
|
||
Maintainer | ||
---------- | ||
|
||
This module is maintained by LOKAVALUTO. | ||
|
||
LOKAVALUTO, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and ecosystem for local complementary currency organizations. |
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,2 @@ | ||
# -*- coding: utf-8 -*- | ||
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,20 @@ | ||
{ | ||
"name": "lcc_wallet_qr", | ||
"summary": "Generation of a QR code for LCC numeric wallets", | ||
"author": "Lokavaluto", | ||
"website": "https://lokavaluto.fr", | ||
"category": "Website", | ||
"version": "12.0.1.0.0", | ||
# any module necessary for this one to work correctly | ||
"depends": [ | ||
"base", | ||
"lcc_lokavaluto_app_connection", | ||
], | ||
# always loaded | ||
"data": [ | ||
"views/lcc_backend.xml", | ||
"data/res_partner_backend_data.xml", | ||
], | ||
# only loaded in demonstration mode | ||
"demo": [], | ||
} |
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<data> | ||
<record id="ir_cron_generate_missing_wallet_qr_codes" model="ir.cron"> | ||
<field name="name">Wallet: generate missing QR codes</field> | ||
<field name="model_id" ref="lcc_lokavaluto_app_connection.model_res_partner_backend" /> | ||
<field name="state">code</field> | ||
<field name="code">model._cron_generate_missing_qr()</field> | ||
<field name="interval_type">days</field> | ||
<field name="numbercall">-1</field> | ||
<field name="active">0</field> | ||
</record> | ||
</data> | ||
</odoo> |
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,2 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import res_partner_backend |
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,68 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
try: | ||
import qrcode | ||
except ImportError: | ||
qrcode = None | ||
try: | ||
import base64 | ||
except ImportError: | ||
base64 = None | ||
from io import BytesIO | ||
|
||
from odoo import models, fields, api,_ | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class ResPartnerBackend(models.Model): | ||
_inherit = "res.partner.backend" | ||
|
||
qr = fields.Binary(string="Wallet QR code", store=True, copy=False) | ||
|
||
@api.model | ||
def create(self, vals): | ||
res = super(ResPartnerBackend, self).create(vals) | ||
res.generate_qr() | ||
return res | ||
|
||
def _get_qr_content(self): | ||
self.ensure_one() | ||
content = { | ||
"rp": self.partner_id.id, | ||
"rpb": self.name, | ||
} | ||
return content | ||
|
||
def generate_qr(self): | ||
if qrcode and base64: | ||
for record in self: | ||
qr = qrcode.QRCode( | ||
version=1, | ||
error_correction=qrcode.constants.ERROR_CORRECT_L, | ||
box_size=10, | ||
border=2, | ||
) | ||
qr_content = record._get_qr_content() | ||
|
||
qr.add_data(qr_content) | ||
qr.make(fit=True) | ||
|
||
img = qr.make_image() | ||
temp = BytesIO() | ||
img.save(temp, format="PNG") | ||
qr_image = base64.b64encode(temp.getvalue()) | ||
record.write( | ||
{ | ||
"qr": qr_image, | ||
} | ||
) | ||
else: | ||
raise UserError( | ||
_( | ||
"Necessary requirements are not satisfied - Need qrcode and base64 Python libraries" | ||
) | ||
) | ||
|
||
@api.model | ||
def _cron_generate_missing_qr(self): | ||
self.search([("qr", "=", False)]).generate_qr() |
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="lcc_backend_form_qr_view" model="ir.ui.view"> | ||
<field name="name">lcc.backend.qr.form.view</field> | ||
<field name="model">res.partner.backend</field> | ||
<field name="inherit_id" ref="lcc_lokavaluto_app_connection.lcc_backend_form_view" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//group[@name='general_info']" position="before"> | ||
<button name="generate_qr" type="object" class="btn-box ml-3" icon="fa-qrcode"> | ||
Generate new QR | ||
</button> | ||
</xpath> | ||
<xpath expr="//field[@name='status']" position="after"> | ||
<field name="qr" readonly="True" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |