Browse Source

[UPDT] : Bug Fixed 'customer_product_qrcode'

pull/257/head
AjmalCybro 2 years ago
parent
commit
91a5c41f12
  1. 2
      customer_product_qrcode/__init__.py
  2. 6
      customer_product_qrcode/__manifest__.py
  3. 6
      customer_product_qrcode/doc/RELEASE_NOTES.md
  4. 3
      customer_product_qrcode/models/__init__.py
  5. 36
      customer_product_qrcode/models/models.py
  6. 2
      customer_product_qrcode/report/__init__.py
  7. 30
      customer_product_qrcode/report/paperformat.xml
  8. 8
      customer_product_qrcode/report/parser.py
  9. 47
      customer_product_qrcode/report/report.xml
  10. 49
      customer_product_qrcode/report/template.xml
  11. 51
      customer_product_qrcode/views/view.xml

2
customer_product_qrcode/__init__.py

@ -3,7 +3,7 @@
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER

6
customer_product_qrcode/__manifest__.py

@ -3,7 +3,7 @@
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
@ -19,12 +19,12 @@
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
{
'name': 'Customer and Product QR Code Generator',
'version': '16.0.1.0.0',
'summary': 'Generate Unique QR Codes for Customers and Products',
'description': 'QR Code, QR Code Generator, Odoo QR Code Generator, Customer QR Code, Product QR Code, QR, QR Code Odoo',
'description': 'QR Code, QR Code Generator, Odoo QR Code Generator,'
' Customer QR Code, Product QR Code, QR, QR Code Odoo',
'category': 'Extra Tools',
'author': 'Cybrosys Techno solutions',
'maintainer': 'Cybrosys Techno Solutions',

6
customer_product_qrcode/doc/RELEASE_NOTES.md

@ -3,4 +3,8 @@
#### 03.10.2022
#### Version 16.0.1.0.0
#### ADD
- Initial commit for customer_product_qrcode
- Initial commit for customer_product_qrcode
#### 29.05.2023
#### Version 16.0.1.0.1
#### FIX
- Fixed the issue in Save Function

3
customer_product_qrcode/models/__init__.py

@ -3,7 +3,7 @@
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
@ -19,5 +19,4 @@
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from . import models

36
customer_product_qrcode/models/models.py

@ -3,7 +3,7 @@
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
@ -19,7 +19,6 @@
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
try:
import qrcode
except ImportError:
@ -30,26 +29,28 @@ except ImportError:
base64 = None
from io import BytesIO
from odoo import models, fields, api, _, SUPERUSER_ID
from odoo import models, fields, api, _
from odoo.exceptions import UserError
class Partners(models.Model):
"""Extends the res.partner model to include QR code functionality."""
_inherit = 'res.partner'
sequence = fields.Char(string="QR Sequence", readonly=True)
qr = fields.Binary(string="QR Code")
def init(self):
"""Initialize the QR sequence for customer partners with a combination
of 'DEF', partner's name (without spaces), and partner's ID."""
for record in self.env['res.partner'].search(
[('customer_rank', '=', True)]):
print(record,"record")
name = record.name.replace(" ", "")
print(name)
record.sequence = 'DEF' + name.upper() + str(record.id)
@api.model
def create(self, vals):
"""Create a new partner record and assign a unique QR sequence to it."""
prefix = self.env['ir.config_parameter'].sudo().get_param(
'customer_product_qr.config.customer_prefix')
if not prefix:
@ -62,6 +63,8 @@ class Partners(models.Model):
@api.depends('sequence')
def generate_qr(self):
"""Generate a QR code based on the partner's sequence and store it in
the 'qr' field of the partner record."""
if qrcode and base64:
if not self.sequence:
prefix = self.env['ir.config_parameter'].sudo().get_param(
@ -80,14 +83,11 @@ class Partners(models.Model):
)
qr.add_data(self.sequence)
qr.make(fit=True)
img = qr.make_image()
temp = BytesIO()
img.save(temp, format="PNG")
qr_image = base64.b64encode(temp.getvalue())
# print(qr_image,"qr")
self.write({'qr': qr_image})
print(qr,"qr")
return self.env.ref(
'customer_product_qrcode.print_qr').report_action(self, data={
'data': self.id, 'type': 'cust'})
@ -101,6 +101,7 @@ class Partners(models.Model):
class Products(models.Model):
"""Extends the product.product model to include QR code functionality."""
_inherit = 'product.product'
sequence = fields.Char(string="QR Sequence", readonly=True)
@ -108,6 +109,8 @@ class Products(models.Model):
@api.model
def create(self, vals):
"""Create a new product and assign a unique QR sequence and QR code
to it."""
prefix = self.env['ir.config_parameter'].sudo().get_param(
'customer_product_qr.config.product_prefix')
if not prefix:
@ -124,7 +127,6 @@ class Products(models.Model):
)
qr.add_data(vals['sequence'])
qr.make(fit=True)
img = qr.make_image()
temp = BytesIO()
img.save(temp, format="PNG")
@ -134,6 +136,8 @@ class Products(models.Model):
@api.depends('sequence')
def generate_qr(self):
"""Generate a QR code based on the product's sequence and store it in
the 'qr' field of the product."""
if qrcode and base64:
if not self.sequence:
prefix = self.env['ir.config_parameter'].sudo().get_param(
@ -152,7 +156,6 @@ class Products(models.Model):
)
qr.add_data(self.sequence)
qr.make(fit=True)
img = qr.make_image()
temp = BytesIO()
img.save(temp, format="PNG")
@ -166,17 +169,21 @@ class Products(models.Model):
_('Necessary Requirements To Run This Operation Is Not Satisfied'))
def get_product_by_qr(self, **args):
"""Retrieve a product based on the provided QR sequence."""
return self.env['product.product'].search(
[('sequence', '=', self.id), ], limit=1).id
class ProductTemplate(models.Model):
"""Extends the product.template model to generate QR codes for all
related product variants."""
_inherit = 'product.template'
def generate_qr(self):
"""Generate QR codes for all product variants associated with the
product template."""
product = self.env['product.product'].search(
[('product_tmpl_id', '=', self.id)])
print(product,"product")
[('product_tmpl_id', '=', self.id), ])
for rec in product:
rec.generate_qr()
return self.env.ref('customer_product_qrcode.print_qr2').report_action(
@ -184,12 +191,15 @@ class ProductTemplate(models.Model):
class ResConfigSettings(models.TransientModel):
"""Extends the res.config.settings model to include configuration
settings for QR code prefixes."""
_inherit = 'res.config.settings'
customer_prefix = fields.Char(string="Customer QR Prefix")
product_prefix = fields.Char(string="Product QR Prefix")
def get_values(self):
"""fRetrieve the current configuration values for QR code prefixes."""
res = super(ResConfigSettings, self).get_values()
customer_prefix = self.env["ir.config_parameter"].get_param(
"customer_product_qr.config.customer_prefix")
@ -204,7 +214,9 @@ class ResConfigSettings(models.TransientModel):
return res
def set_values(self):
"""Set the configuration values for QR code prefixes."""
self.env['ir.config_parameter'].sudo().set_param(
'customer_product_qr.config.customer_prefix', self.customer_prefix)
self.env['ir.config_parameter'].sudo().set_param(
'customer_product_qr.config.product_prefix', self.product_prefix)
super(ResConfigSettings, self).set_values()

2
customer_product_qrcode/report/__init__.py

@ -3,7 +3,7 @@
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER

30
customer_product_qrcode/report/paperformat.xml

@ -1,17 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="customer_product_qrcode.customer_badge_paperformat" model="report.paperformat">
<field name="name">PDF Report</field>
<field name="default" eval="False" />
<field name="format">custom</field>
<field name="page_height">100</field>
<field name="page_width">100</field>
<field name="orientation">Portrait</field>
<field name="margin_top">10</field>
<field name="margin_bottom">0</field>
<field name="margin_left">10</field>
<field name="margin_right">10</field>
<field name="header_line" eval="False" />
<field name="header_spacing">80</field>
<field name="dpi">90</field>
<record id="customer_product_qrcode.customer_badge_paperformat"
model="report.paperformat">
<field name="name">PDF Report</field>
<field name="default" eval="False"/>
<field name="format">custom</field>
<field name="page_height">100</field>
<field name="page_width">100</field>
<field name="orientation">Portrait</field>
<field name="margin_top">10</field>
<field name="margin_bottom">0</field>
<field name="margin_left">10</field>
<field name="margin_right">10</field>
<field name="header_line" eval="False"/>
<field name="header_spacing">80</field>
<field name="dpi">90</field>
</record>
</odoo>

8
customer_product_qrcode/report/parser.py

@ -3,7 +3,7 @@
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
@ -24,15 +24,17 @@ from odoo.http import request
class CustomerBadge(models.AbstractModel):
"""Abstract model for generating the customer QR template report."""
_name = 'report.customer_product_qrcode.customer_qr_template'
@api.model
def _get_report_values(self, docids, data=None):
print(data,"data")
"""Get the report values for generating the customer QR template."""
if data['type'] == 'cust':
dat = [request.env['res.partner'].browse(data['data'])]
elif data['type'] == 'all':
dat = [request.env['product.product'].search([('product_tmpl_id', '=', data['data'])])]
dat = [request.env['product.product'].search(
[('product_tmpl_id', '=', data['data'])])]
else:
dat = request.env['product.product'].browse(data['data'])
return {

47
customer_product_qrcode/report/report.xml

@ -2,37 +2,42 @@
<odoo>
<data>
<report id="customer_product_qrcode.print_qr"
model="res.partner"
name="customer_product_qrcode.customer_qr_template"
file="customer_product_qrcode.customer_qr_template"
string="Badge"
report_type="qweb-pdf"
model="res.partner"
name="customer_product_qrcode.customer_qr_template"
file="customer_product_qrcode.customer_qr_template"
string="Badge"
report_type="qweb-pdf"
menu="False"
/>
<report id="customer_product_qrcode.print_qr1"
model="product.product"
name="customer_product_qrcode.customer_qr_template"
file="customer_product_qrcode.customer_qr_template"
string="Product Badge"
report_type="qweb-pdf"
model="product.product"
name="customer_product_qrcode.customer_qr_template"
file="customer_product_qrcode.customer_qr_template"
string="Product Badge"
report_type="qweb-pdf"
menu="False"
/>
<report id="customer_product_qrcode.print_qr2"
model="product.template"
name="customer_product_qrcode.customer_qr_template"
file="customer_product_qrcode.customer_qr_template"
string="Product Badge"
report_type="qweb-pdf"
model="product.template"
name="customer_product_qrcode.customer_qr_template"
file="customer_product_qrcode.customer_qr_template"
string="Product Badge"
report_type="qweb-pdf"
menu="False"
/>
<record id="customer_product_qrcode.print_qr" model="ir.actions.report">
<field name="paperformat_id" ref="customer_product_qrcode.customer_badge_paperformat"/>
<field name="paperformat_id"
ref="customer_product_qrcode.customer_badge_paperformat"/>
</record>
<record id="customer_product_qrcode.print_qr1" model="ir.actions.report">
<field name="paperformat_id" ref="customer_product_qrcode.customer_badge_paperformat"/>
<record id="customer_product_qrcode.print_qr1"
model="ir.actions.report">
<field name="paperformat_id"
ref="customer_product_qrcode.customer_badge_paperformat"/>
</record>
<record id="customer_product_qrcode.print_qr2" model="ir.actions.report">
<field name="paperformat_id" ref="customer_product_qrcode.customer_badge_paperformat"/>
<record id="customer_product_qrcode.print_qr2"
model="ir.actions.report">
<field name="paperformat_id"
ref="customer_product_qrcode.customer_badge_paperformat"/>
</record>
</data>
</odoo>
</odoo>

49
customer_product_qrcode/report/template.xml

@ -8,37 +8,38 @@
<t t-call="web.internal_layout">
<style>
table{
border:1px solid black !important;
height:370px;
width:370px;
border:1px solid black !important;
height:370px;
width:370px;
}
tr{
border:1px solid black !important;
border:1px solid black !important;
}
td{
border:1px solid black !important;
font-size:30px;
border:1px solid black !important;
font-size:30px;
}
</style>
<div class="page">
<center>
<table>
<tr>
<td style="text-align:center;">
<span t-esc="record.name" style="float:center;"/>
</td>
</tr>
<tr>
<td>
<center>
<span t-field="record.qr" t-options="{'widget': 'image'}"/>
<!-- <img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s'%('QR', record.qr, 130, 130)"-->
<!-- style="height:280px;width:280px;float:center;"/><br/>-->
<span t-esc="record.sequence" style="float:center;"/>
</center>
</td>
</tr>
</table>
<table>
<tr>
<td style="text-align:center;">
<span t-esc="record.name"
style="float:center;"/>
</td>
</tr>
<tr>
<td>
<center>
<span t-field="record.qr"
t-options="{'widget': 'image'}"/>
<span t-esc="record.sequence"
style="float:center;"/>
</center>
</td>
</tr>
</table>
</center>
</div>
</t>
@ -47,4 +48,4 @@
</t>
</template>
</data>
</odoo>
</odoo>

51
customer_product_qrcode/views/view.xml

@ -52,36 +52,37 @@
<record id="settings_form_inherit_for_qr" model="ir.ui.view">
<field name="name">res.config.inherit.qr</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
<field name="inherit_id"
ref="base_setup.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@id='companies']" position="after">
<div id="setup_qrcode">
<h2>Setup QRCode</h2>
<div class="row mt16 o_settings_container">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_right_pane">
<label string="Prefixes"
for="customer_prefix"/>
<span class="fa fa-lg"/>
<div class="text-muted">
Set your unique prefix.
</div>
<div class="content-group">
<div class="mt16 row">
<label for="customer_prefix"
class="o_light_label"/>
<field name="customer_prefix"
class="oe_inline"/>
<label for="product_prefix"
class="col-xs-3 col-md-6 o_light_label"/>
<field name="product_prefix"
class="oe_inline"/>
</div>
<div id="setup_qrcode">
<h2>Setup QRCode</h2>
<div class="row mt16 o_settings_container">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_right_pane">
<label string="Prefixes"
for="customer_prefix"/>
<span class="fa fa-lg"/>
<div class="text-muted">
Set your unique prefix.
</div>
<div class="content-group">
<div class="mt16 row">
<label for="customer_prefix"
class="o_light_label"/>
<field name="customer_prefix"
class="oe_inline"/>
<label for="product_prefix"
class="col-xs-3 col-md-6 o_light_label"/>
<field name="product_prefix"
class="oe_inline"/>
</div>
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
@ -90,7 +91,7 @@
<record id="customer_sequence_id" model="ir.sequence">
<field name="name">customer_sequence</field>
<field name="code">res.partner</field>
<field name="prefix"></field>
<field name="prefix"/>
<field name="padding">5</field>
</record>
</data>
@ -98,7 +99,7 @@
<record id="product_sequence_id" model="ir.sequence">
<field name="name">product_sequence</field>
<field name="code">product.product</field>
<field name="prefix"></field>
<field name="prefix"/>
<field name="padding">5</field>
</record>
</data>

Loading…
Cancel
Save