diff --git a/customer_product_qrcode/__init__.py b/customer_product_qrcode/__init__.py new file mode 100755 index 000000000..7db66946c --- /dev/null +++ b/customer_product_qrcode/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +from . import models +from . import report diff --git a/customer_product_qrcode/__manifest__.py b/customer_product_qrcode/__manifest__.py new file mode 100755 index 000000000..a946c113a --- /dev/null +++ b/customer_product_qrcode/__manifest__.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2018-TODAY Cybrosys Technologies(). +# Author: Muhammed Nishad T K +# This program is free software: you can modify +# it under the terms of the GNU Affero General Public License (AGPL) as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Customer and Product QR Code Generator', + 'version': '11.0.1.0.0', + 'summary': 'Generate Unique QR Codes for Customers and Products', + 'category': 'Extra Tools', + 'author': 'Cybrosys Techno solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'website': 'https://www.cybrosys.com', + 'depends': ['base', 'sale', 'stock', + ], + 'data': [ + 'views/view.xml', + 'report/paperformat.xml', + 'report/report.xml', + 'report/template.xml', + ], + "qweb": [ + ], + 'images': ['static/description/banner.jpg'], + 'installable': True, + 'application': False, + 'auto_install': False, + 'license': 'AGPL-3', +} diff --git a/customer_product_qrcode/doc/RELEASE_NOTES.md b/customer_product_qrcode/doc/RELEASE_NOTES.md new file mode 100755 index 000000000..01c92a17c --- /dev/null +++ b/customer_product_qrcode/doc/RELEASE_NOTES.md @@ -0,0 +1,6 @@ +## Module + +#### 22.10.2018 +#### Version 11.0.1.0.0 +##### ADD +- Initial commit for Customer and Product QR Module \ No newline at end of file diff --git a/customer_product_qrcode/models/__init__.py b/customer_product_qrcode/models/__init__.py new file mode 100755 index 000000000..a0fdc10fe --- /dev/null +++ b/customer_product_qrcode/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import models diff --git a/customer_product_qrcode/models/models.py b/customer_product_qrcode/models/models.py new file mode 100755 index 000000000..ec5aa51c2 --- /dev/null +++ b/customer_product_qrcode/models/models.py @@ -0,0 +1,157 @@ +# -*- 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, _, SUPERUSER_ID +from odoo.exceptions import UserError + + +class Partners(models.Model): + _inherit = 'res.partner' + + sequence = fields.Char(string="QR Sequence", readonly=True) + qr = fields.Binary(string="QR Code") + + def init(self): + for record in self.env['res.partner'].search([('customer', '=', True)]): + name = record.name.replace(" ", "") + record.sequence = 'DEF' + name.upper()+str(record.id) + + @api.model + def create(self, vals): + prefix = str(self.env['ir.config_parameter'].sudo().get_param('customer_product_qr.config.customer_prefix')) + if not prefix: + raise UserError(_('Set A Customer Prefix In General Settings')) + seq = prefix + self.env['ir.sequence'].next_by_code('res.partner') or '/' + vals['sequence'] = seq + return super(Partners, self).create(vals) + + @api.depends('sequence') + def generate_qr(self): + if qrcode and base64: + if not self.sequence: + prefix = str(self.env['ir.config_parameter'].sudo().get_param('customer_product_qr.config.customer_prefix')) + if not prefix: + raise UserError(_('Set A Customer Prefix In General Settings')) + self.sequence = prefix + self.env['ir.sequence'].next_by_code('res.partner') or '/' + qr = qrcode.QRCode( + version=1, + error_correction=qrcode.constants.ERROR_CORRECT_L, + box_size=10, + border=4, + ) + 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()) + self.write({'qr': qr_image}) + return self.env.ref('customer_product_qrcode.print_qr').report_action(self, data={'data': self.id, 'type': 'cust'}) + else: + raise UserError(_('Necessary Requirements To Run This Operation Is Not Satisfied')) + + @api.multi + def get_partner_by_qr(self, **args): + return self.env['res.partner'].search([('sequence', '=', self.id), ], limit=1).id + + +class Products(models.Model): + _inherit = 'product.product' + + sequence = fields.Char(string="QR Sequence", readonly=True) + qr = fields.Binary(string="QR Code") + + def init(self): + for record in self.env['product.product'].search([]): + name = record.name.replace(" ", "") + record.sequence = 'DEF' + name.upper()+str(record.id) + + @api.model + def create(self, vals): + prefix = str(self.env['ir.config_parameter'].sudo().get_param('customer_product_qr.config.product_prefix')) + if not prefix: + raise UserError(_('Set A Product Prefix In General Settings')) + seq = prefix + self.env['ir.sequence'].next_by_code('product.product') or '/' + vals['sequence'] = seq + qr = qrcode.QRCode( + version=1, + error_correction=qrcode.constants.ERROR_CORRECT_L, + box_size=10, + border=4, + ) + qr.add_data(vals['sequence']) + qr.make(fit=True) + + img = qr.make_image() + temp = BytesIO() + img.save(temp, format="PNG") + qr_image = base64.b64encode(temp.getvalue()) + vals.update({'qr': qr_image}) + return super(Products, self).create(vals) + + @api.depends('sequence') + def generate_qr(self): + if not self.sequence: + prefix = str(self.env['ir.config_parameter'].sudo().get_param('customer_product_qr.config.product_prefix')) + if not prefix: + raise UserError(_('Set A Product Prefix In General Settings')) + self.sequence = prefix + self.env['ir.sequence'].next_by_code('product.product') or '/' + qr = qrcode.QRCode( + version=1, + error_correction=qrcode.constants.ERROR_CORRECT_L, + box_size=10, + border=4, + ) + 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()) + self.write({'qr': qr_image}) + return self.env.ref('customer_product_qrcode.print_qr1').report_action(self, data={'data': self.id, 'type': 'prod'}) + + @api.multi + def get_product_by_qr(self, **args): + return self.env['product.product'].search([('sequence', '=', self.id), ], limit=1).id + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + def generate_qr(self): + return self.env.ref('customer_product_qrcode.print_qr1').report_action(self, data={'data': self.id, 'type': 'all'}) + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + customer_prefix = fields.Char(string="Customer QR Prefix") + product_prefix = fields.Char(string="Product QR Prefix") + + def get_values(self): + res = super(ResConfigSettings, self).get_values() + customer_prefix = self.env["ir.config_parameter"].get_param("customer_product_qr.config.customer_prefix") + product_prefix = self.env["ir.config_parameter"].get_param("customer_product_qr.config.product_prefix") + res.update({ + 'customer_prefix': customer_prefix if type(customer_prefix) else False, + 'product_prefix': product_prefix if type(product_prefix) else False + } + ) + return res + + def set_values(self): + 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) diff --git a/customer_product_qrcode/readme.rst b/customer_product_qrcode/readme.rst new file mode 100755 index 000000000..5ba2d5e87 --- /dev/null +++ b/customer_product_qrcode/readme.rst @@ -0,0 +1,30 @@ +===================================== +Customer and Product QRCode Generator +===================================== +The Customer and Product QRCode Generator Helps You to Generate Unique +QR Codes to your Products or Customers +Tech +==== +* [Python] - Models +* [XML] - Odoo views + +Installation +============ +- www.odoo.com/documentation/11.0/setup/install.html +- Install our custom addon + +Bug Tracker +=========== +Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. + +Credits +======= +* Cybrosys Techno Solutions + +Maintainer +---------- + +This module is maintained by Cybrosys Technologies. + +For support and more information, please visit https://www.cybrosys.com. + diff --git a/customer_product_qrcode/report/__init__.py b/customer_product_qrcode/report/__init__.py new file mode 100755 index 000000000..41d355cae --- /dev/null +++ b/customer_product_qrcode/report/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import parser diff --git a/customer_product_qrcode/report/paperformat.xml b/customer_product_qrcode/report/paperformat.xml new file mode 100755 index 000000000..dab9a0264 --- /dev/null +++ b/customer_product_qrcode/report/paperformat.xml @@ -0,0 +1,17 @@ + + + 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 new file mode 100755 index 000000000..b71920663 --- /dev/null +++ b/customer_product_qrcode/report/parser.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from odoo import models, api +from odoo.http import request + + +class CustomerBadge(models.AbstractModel): + _name = 'report.customer_product_qrcode.customer_qr_template' + + @api.model + def get_report_values(self, docids, data=None): + if data['type'] == 'cust': + dat = [request.env['res.partner'].browse(data['data'])] + print(dat) + elif data['type'] == 'all': + dat = [request.env['product.product'].search([('product_tmpl_id', '=', data['data'])])] + else: + dat = request.env['product.product'].browse(data['data']) + return { + 'data': dat, + } diff --git a/customer_product_qrcode/report/report.xml b/customer_product_qrcode/report/report.xml new file mode 100755 index 000000000..c0139a1e6 --- /dev/null +++ b/customer_product_qrcode/report/report.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/customer_product_qrcode/report/template.xml b/customer_product_qrcode/report/template.xml new file mode 100755 index 000000000..aee077c66 --- /dev/null +++ b/customer_product_qrcode/report/template.xml @@ -0,0 +1,48 @@ + + + + + + \ No newline at end of file diff --git a/customer_product_qrcode/static/description/banner.jpg b/customer_product_qrcode/static/description/banner.jpg new file mode 100755 index 000000000..9b8e25189 Binary files /dev/null and b/customer_product_qrcode/static/description/banner.jpg differ diff --git a/customer_product_qrcode/static/description/cybro-service.png b/customer_product_qrcode/static/description/cybro-service.png new file mode 100755 index 000000000..ae68daed4 Binary files /dev/null and b/customer_product_qrcode/static/description/cybro-service.png differ diff --git a/customer_product_qrcode/static/description/cybro_logo.png b/customer_product_qrcode/static/description/cybro_logo.png new file mode 100755 index 000000000..bb309114c Binary files /dev/null and b/customer_product_qrcode/static/description/cybro_logo.png differ diff --git a/customer_product_qrcode/static/description/icon.png b/customer_product_qrcode/static/description/icon.png new file mode 100755 index 000000000..6b05068e6 Binary files /dev/null and b/customer_product_qrcode/static/description/icon.png differ diff --git a/customer_product_qrcode/static/description/image1.jpg b/customer_product_qrcode/static/description/image1.jpg new file mode 100755 index 000000000..18de36186 Binary files /dev/null and b/customer_product_qrcode/static/description/image1.jpg differ diff --git a/customer_product_qrcode/static/description/image2.jpg b/customer_product_qrcode/static/description/image2.jpg new file mode 100755 index 000000000..7d6b56560 Binary files /dev/null and b/customer_product_qrcode/static/description/image2.jpg differ diff --git a/customer_product_qrcode/static/description/image3.jpg b/customer_product_qrcode/static/description/image3.jpg new file mode 100755 index 000000000..b2bd13c0c Binary files /dev/null and b/customer_product_qrcode/static/description/image3.jpg differ diff --git a/customer_product_qrcode/static/description/image4.png b/customer_product_qrcode/static/description/image4.png new file mode 100755 index 000000000..388c934ab Binary files /dev/null and b/customer_product_qrcode/static/description/image4.png differ diff --git a/customer_product_qrcode/static/description/index.html b/customer_product_qrcode/static/description/index.html new file mode 100755 index 000000000..65281327f --- /dev/null +++ b/customer_product_qrcode/static/description/index.html @@ -0,0 +1,110 @@ +
+
+

Customer and Product QR Code Generator

+

Generate Unique QR Codes for Customers and Products

+

Cybrosys Technologies

+
+
+
+

If QR codes aren't the part of your current marketing strategy, you might be missing the large chunks of benefits. Use QR codes to generate customer interest, drive traffic, and increase sales via print, online, or email. The Customer and Product QR Code Generator allows the users to scan QR codes simply and easily from within your browser. This module helps to set up a unique QR code to both your products and customers.

+ Features: +
    +
  • Unique QR code for products and customers.
  • +
  • Enables to configure a word prefix to QR code for unique identification.
  • +
  • QR code for individual product variants.
  • +
  • QR code for whole product template variants.
  • +
+
+
+
+
+

+ Set the product and customer prefixes from General Settings Menu. + Set a Unique and Denotable Prefix to Your Customers. +

+
+
+
+ +
+
+
+
+
+
+ +
+
+
+

+ Goto The Customer or Product Form.Click the Generate QR Button. + The QR Sequence will be generated and the QR Code will be printed as a PDF. +

+
+
+
+
+
+
+

+ Set the product and customer prefixes from General Settings Menu. + Set a Unique and Denotable Prefix to Your Customers. +

+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+

+ Each Customer or Product will have a unique qr sequence. Simply go to scan from menu bar and grant access to your device camera, you’re ready to scan a QR code using your laptop or mobile devices. +

+
+
+
+
+

+

+
+
+
+ +
+

Need Any Help?

+ +
+ + + diff --git a/customer_product_qrcode/views/view.xml b/customer_product_qrcode/views/view.xml new file mode 100755 index 000000000..c7dafd2b1 --- /dev/null +++ b/customer_product_qrcode/views/view.xml @@ -0,0 +1,90 @@ + + + + + res.partner.form.qr.inherit + res.partner + + + + + + + + + + + + product.product.form.qr.inherit + product.product + + + + + + + + + + + + product.template.form.qr.inherit + product.template + + + + + + + + + res.config.inherit.qr + res.config.settings + + + +
+
+

Setup QRCode

+
+
+
+
+
+
+
+
+
+
+
+
+ + + customer_sequence + res.partner + + 5 + + + + + product_sequence + product.product + + 5 + + +
\ No newline at end of file