From 91a5c41f12057560d1a21a04be90b8ec5bf64fc1 Mon Sep 17 00:00:00 2001 From: AjmalCybro Date: Mon, 29 May 2023 19:21:53 +0530 Subject: [PATCH] [UPDT] : Bug Fixed 'customer_product_qrcode' --- customer_product_qrcode/__init__.py | 2 +- customer_product_qrcode/__manifest__.py | 6 +-- customer_product_qrcode/doc/RELEASE_NOTES.md | 6 ++- customer_product_qrcode/models/__init__.py | 3 +- customer_product_qrcode/models/models.py | 36 ++++++++----- customer_product_qrcode/report/__init__.py | 2 +- .../report/paperformat.xml | 30 ++++++----- customer_product_qrcode/report/parser.py | 8 +-- customer_product_qrcode/report/report.xml | 47 +++++++++-------- customer_product_qrcode/report/template.xml | 49 +++++++++--------- customer_product_qrcode/views/view.xml | 51 ++++++++++--------- 11 files changed, 133 insertions(+), 107 deletions(-) diff --git a/customer_product_qrcode/__init__.py b/customer_product_qrcode/__init__.py index 73aefe930..17890c0a2 100755 --- a/customer_product_qrcode/__init__.py +++ b/customer_product_qrcode/__init__.py @@ -3,7 +3,7 @@ # # Cybrosys Technologies Pvt. Ltd. # -# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Copyright (C) 2023-TODAY Cybrosys Technologies() # Author: Cybrosys Techno Solutions() # # You can modify it under the terms of the GNU LESSER diff --git a/customer_product_qrcode/__manifest__.py b/customer_product_qrcode/__manifest__.py index 7c538d769..c28d62009 100755 --- a/customer_product_qrcode/__manifest__.py +++ b/customer_product_qrcode/__manifest__.py @@ -3,7 +3,7 @@ # # Cybrosys Technologies Pvt. Ltd. # -# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Copyright (C) 2023-TODAY Cybrosys Technologies() # Author: Cybrosys Techno Solutions() # # You can modify it under the terms of the GNU LESSER @@ -19,12 +19,12 @@ # If not, see . # ############################################################################# - { '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', diff --git a/customer_product_qrcode/doc/RELEASE_NOTES.md b/customer_product_qrcode/doc/RELEASE_NOTES.md index cbd51ab03..e20da985c 100644 --- a/customer_product_qrcode/doc/RELEASE_NOTES.md +++ b/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 \ No newline at end of file +- Initial commit for customer_product_qrcode +#### 29.05.2023 +#### Version 16.0.1.0.1 +#### FIX +- Fixed the issue in Save Function \ No newline at end of file diff --git a/customer_product_qrcode/models/__init__.py b/customer_product_qrcode/models/__init__.py index f2c5a4636..7b2c59c1c 100755 --- a/customer_product_qrcode/models/__init__.py +++ b/customer_product_qrcode/models/__init__.py @@ -3,7 +3,7 @@ # # Cybrosys Technologies Pvt. Ltd. # -# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Copyright (C) 2023-TODAY Cybrosys Technologies() # Author: Cybrosys Techno Solutions() # # You can modify it under the terms of the GNU LESSER @@ -19,5 +19,4 @@ # If not, see . # ############################################################################# - from . import models diff --git a/customer_product_qrcode/models/models.py b/customer_product_qrcode/models/models.py index 2b198c7ad..a965694b3 100755 --- a/customer_product_qrcode/models/models.py +++ b/customer_product_qrcode/models/models.py @@ -3,7 +3,7 @@ # # Cybrosys Technologies Pvt. Ltd. # -# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Copyright (C) 2023-TODAY Cybrosys Technologies() # Author: Cybrosys Techno Solutions() # # You can modify it under the terms of the GNU LESSER @@ -19,7 +19,6 @@ # If not, see . # ############################################################################# - 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() diff --git a/customer_product_qrcode/report/__init__.py b/customer_product_qrcode/report/__init__.py index f4ba7d127..f2da5230e 100755 --- a/customer_product_qrcode/report/__init__.py +++ b/customer_product_qrcode/report/__init__.py @@ -3,7 +3,7 @@ # # Cybrosys Technologies Pvt. Ltd. # -# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Copyright (C) 2023-TODAY Cybrosys Technologies() # Author: Cybrosys Techno Solutions() # # You can modify it under the terms of the GNU LESSER diff --git a/customer_product_qrcode/report/paperformat.xml b/customer_product_qrcode/report/paperformat.xml index dab9a0264..64e533a04 100755 --- a/customer_product_qrcode/report/paperformat.xml +++ b/customer_product_qrcode/report/paperformat.xml @@ -1,17 +1,19 @@ + - - PDF Report - - custom - 100 - 100 - Portrait - 10 - 0 - 10 - 10 - - 80 - 90 + + PDF Report + + custom + 100 + 100 + Portrait + 10 + 0 + 10 + 10 + + 80 + 90 \ No newline at end of file diff --git a/customer_product_qrcode/report/parser.py b/customer_product_qrcode/report/parser.py index 233de2361..328f65c8b 100755 --- a/customer_product_qrcode/report/parser.py +++ b/customer_product_qrcode/report/parser.py @@ -3,7 +3,7 @@ # # Cybrosys Technologies Pvt. Ltd. # -# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Copyright (C) 2023-TODAY Cybrosys Technologies() # Author: Cybrosys Techno Solutions() # # 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 { diff --git a/customer_product_qrcode/report/report.xml b/customer_product_qrcode/report/report.xml index 189fd7b67..5311f3bf0 100755 --- a/customer_product_qrcode/report/report.xml +++ b/customer_product_qrcode/report/report.xml @@ -2,37 +2,42 @@ - + - - + + - - + + - \ No newline at end of file + diff --git a/customer_product_qrcode/report/template.xml b/customer_product_qrcode/report/template.xml index 57584ee73..5762847b2 100755 --- a/customer_product_qrcode/report/template.xml +++ b/customer_product_qrcode/report/template.xml @@ -8,37 +8,38 @@
- - - - - - - -
- -
-
- - - - -
-
+ + + + + + + +
+ +
+
+ + +
+
@@ -47,4 +48,4 @@ - \ No newline at end of file + diff --git a/customer_product_qrcode/views/view.xml b/customer_product_qrcode/views/view.xml index b7a10c6aa..fcad2555d 100755 --- a/customer_product_qrcode/views/view.xml +++ b/customer_product_qrcode/views/view.xml @@ -52,36 +52,37 @@ res.config.inherit.qr res.config.settings - + -
-

Setup QRCode

-
-
-
-