16 changed files with 492 additions and 338 deletions
			
			
		| @ -0,0 +1,19 @@ | |||
| <?xml version="1.0" encoding="UTF-8" ?> | |||
| <odoo> | |||
|     <data noupdate="1"> | |||
|         <record id="ir_sequence_customer" model="ir.sequence"> | |||
|             <field name="name">customer_sequence</field> | |||
|             <field name="code">res.partner</field> | |||
|             <field name="prefix"></field> | |||
|             <field name="padding">5</field> | |||
|         </record> | |||
|     </data> | |||
|     <data noupdate="1"> | |||
|         <record id="ir_sequence_product" model="ir.sequence"> | |||
|             <field name="name">product_sequence</field> | |||
|             <field name="code">product.product</field> | |||
|             <field name="prefix"></field> | |||
|             <field name="padding">5</field> | |||
|         </record> | |||
|     </data> | |||
| </odoo> | |||
| @ -1,6 +1,7 @@ | |||
| ## Module <customer_product_qrcode> | |||
| 
 | |||
| #### 18.11.2021 | |||
| #### Version 15.0.1.0.0 | |||
| #### ADD | |||
| - Initial commit for customer_product_qrcode | |||
| #### 10.07.2023 | |||
| #### Version 15.0.2.0.0 | |||
| #### UPDT | |||
| 
 | |||
| -  Code Refactored | |||
|  | |||
| @ -1,205 +0,0 @@ | |||
| # -*- coding: utf-8 -*- | |||
| ############################################################################# | |||
| # | |||
| #    Cybrosys Technologies Pvt. Ltd. | |||
| # | |||
| #    Copyright (C) 2021-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 | |||
| #    GENERAL PUBLIC LICENSE (LGPL v3), Version 3. | |||
| # | |||
| #    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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. | |||
| # | |||
| #    You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE | |||
| #    (LGPL v3) along with this program. | |||
| #    If not, see <http://www.gnu.org/licenses/>. | |||
| # | |||
| ############################################################################# | |||
| 
 | |||
| 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_rank', '=', True)]): | |||
|             name = record.name.replace(" ", "") | |||
|             record.sequence = 'DEF' + name.upper() + str(record.id) | |||
| 
 | |||
|     @api.model | |||
|     def create(self, vals): | |||
|         prefix = 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')) | |||
|         prefix = str(prefix) | |||
|         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 = 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')) | |||
|                 prefix = str(prefix) | |||
|                 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')) | |||
| 
 | |||
|     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") | |||
| 
 | |||
|     @api.model | |||
|     def create(self, vals): | |||
|         prefix = 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')) | |||
|         prefix = str(prefix) | |||
|         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 qrcode and base64: | |||
|             if not self.sequence: | |||
|                 prefix = self.env['ir.config_parameter'].sudo().get_param( | |||
|                     'customer_product_qr.config.product_prefix') | |||
|                 if not prefix: | |||
|                     raise UserError( | |||
|                         _('Set A Customer Prefix In General Settings')) | |||
|                 prefix = str(prefix) | |||
|                 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_qr2').report_action(self, data={ | |||
|                 'data': self.id, 'type': 'prod'}) | |||
|         else: | |||
|             raise UserError( | |||
|                 _('Necessary Requirements To Run This Operation Is Not Satisfied')) | |||
| 
 | |||
|     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): | |||
|         product = self.env['product.product'].search( | |||
|             [('product_tmpl_id', '=', self.id)]) | |||
|         for rec in product: | |||
|             rec.generate_qr() | |||
|         return self.env.ref('customer_product_qrcode.print_qr2').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) | |||
| @ -0,0 +1,114 @@ | |||
| # -*- coding: utf-8 -*- | |||
| ############################################################################# | |||
| # | |||
| #    Cybrosys Technologies Pvt. Ltd. | |||
| # | |||
| #    Copyright (C) 2021-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 | |||
| #    GENERAL PUBLIC LICENSE (LGPL v3), Version 3. | |||
| # | |||
| #    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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. | |||
| # | |||
| #    You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE | |||
| #    (LGPL v3) along with this program. | |||
| #    If not, see <http://www.gnu.org/licenses/>. | |||
| # | |||
| ############################################################################# | |||
| try: | |||
|     import qrcode | |||
| except ImportError: | |||
|     qrcode = None | |||
| try: | |||
|     import base64 | |||
| except ImportError: | |||
|     base64 = None | |||
| from io import BytesIO | |||
| from odoo import api, fields, models, _ | |||
| from odoo.exceptions import UserError | |||
| 
 | |||
| 
 | |||
| class Products(models.Model): | |||
|     """ | |||
|     ProductProduct class for add methods and fields for generate qr code, | |||
|     Methods: | |||
|         create(self, vals): | |||
|             Create method for adding sequence when new product creating. | |||
|         generate_qr(self): | |||
|             QRcode generating method | |||
|         get_product_by_qr(self, **args): | |||
|             For getting qr code info of corresponding product | |||
|     """ | |||
|     _inherit = 'product.product' | |||
| 
 | |||
|     sequence = fields.Char(string="QR Sequence", readonly=True) | |||
|     qr = fields.Binary(string="QR Code") | |||
| 
 | |||
|     @api.model | |||
|     def create(self, vals): | |||
|         """ Supering create method to assign qr code to the product """ | |||
|         prefix = 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')) | |||
|         prefix = str(prefix) | |||
|         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): | |||
|         """ QR code generating method """ | |||
|         if qrcode and base64: | |||
|             if not self.sequence: | |||
|                 prefix = self.env['ir.config_parameter'].sudo().get_param( | |||
|                     'customer_product_qr.config.product_prefix') | |||
|                 if not prefix: | |||
|                     raise UserError( | |||
|                         _('Set A Customer Prefix In General Settings')) | |||
|                 prefix = str(prefix) | |||
|                 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_qr2').report_action(self, data={ | |||
|                 'data': self.id, 'type': 'prod'}) | |||
|         else: | |||
|             raise UserError(_('Necessary Requirements To Run This ' | |||
|                               'Operation Is Not Satisfied')) | |||
| 
 | |||
|     def get_product_by_qr(self, **args): | |||
|         """ To get corresponding product by qr info  """ | |||
|         return self.env['product.product'].search( | |||
|             [('sequence', '=', self.id), ], limit=1).id | |||
| @ -0,0 +1,40 @@ | |||
| # -*- coding: utf-8 -*- | |||
| ############################################################################# | |||
| # | |||
| #    Cybrosys Technologies Pvt. Ltd. | |||
| # | |||
| #    Copyright (C) 2021-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 | |||
| #    GENERAL PUBLIC LICENSE (LGPL v3), Version 3. | |||
| # | |||
| #    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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. | |||
| # | |||
| #    You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE | |||
| #    (LGPL v3) along with this program. | |||
| #    If not, see <http://www.gnu.org/licenses/>. | |||
| # | |||
| ############################################################################# | |||
| from odoo import fields, models | |||
| 
 | |||
| 
 | |||
| class ProductTemplate(models.Model): | |||
|     """ | |||
|     ProductTemplate class for add methods and field for generate qr code, | |||
|     Methods: | |||
|         generate_qr(self): | |||
|             QRcode generating method | |||
|     """ | |||
|     _inherit = 'product.template' | |||
| 
 | |||
|     def generate_qr(self): | |||
|         product = self.env['product.product'].search( | |||
|             [('product_tmpl_id', '=', self.id)]) | |||
|         for rec in product: | |||
|             rec.generate_qr() | |||
|         return self.env.ref('customer_product_qrcode.print_qr2').report_action( | |||
|             self, data={'data': self.id, 'type': 'all'}) | |||
| @ -0,0 +1,62 @@ | |||
| # -*- coding: utf-8 -*- | |||
| ############################################################################# | |||
| # | |||
| #    Cybrosys Technologies Pvt. Ltd. | |||
| # | |||
| #    Copyright (C) 2021-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 | |||
| #    GENERAL PUBLIC LICENSE (LGPL v3), Version 3. | |||
| # | |||
| #    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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. | |||
| # | |||
| #    You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE | |||
| #    (LGPL v3) along with this program. | |||
| #    If not, see <http://www.gnu.org/licenses/>. | |||
| # | |||
| ############################################################################# | |||
| from odoo import fields, models | |||
| 
 | |||
| 
 | |||
| class ResConfigSettings(models.TransientModel): | |||
|     """ | |||
|     ResConfigSettings class for add methods and field for generate qr code | |||
|     options in general settings, | |||
|     Methods: | |||
|         get_values(self): | |||
|             For getting values from ResConfigSettings Transient model | |||
|         set_values(self): | |||
|             For setting values for ResConfigSettings Transient model, ie saving | |||
|             the changes that made from general settings. | |||
|     """ | |||
|     _inherit = 'res.config.settings' | |||
| 
 | |||
|     customer_prefix = fields.Char(string="Customer QR Prefix") | |||
|     product_prefix = fields.Char(string="Product QR Prefix") | |||
| 
 | |||
|     def get_values(self): | |||
|         """ For getting values from ResConfigSettings Transient model """ | |||
|         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): | |||
|         """ Saving the changes made from general settings """ | |||
|         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() | |||
| @ -0,0 +1,110 @@ | |||
| # -*- coding: utf-8 -*- | |||
| ############################################################################# | |||
| # | |||
| #    Cybrosys Technologies Pvt. Ltd. | |||
| # | |||
| #    Copyright (C) 2021-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 | |||
| #    GENERAL PUBLIC LICENSE (LGPL v3), Version 3. | |||
| # | |||
| #    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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. | |||
| # | |||
| #    You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE | |||
| #    (LGPL v3) along with this program. | |||
| #    If not, see <http://www.gnu.org/licenses/>. | |||
| # | |||
| ############################################################################# | |||
| try: | |||
|     import qrcode | |||
| except ImportError: | |||
|     qrcode = None | |||
| try: | |||
|     import base64 | |||
| except ImportError: | |||
|     base64 = None | |||
| from io import BytesIO | |||
| 
 | |||
| from odoo import api, fields, models, _ | |||
| from odoo.exceptions import UserError | |||
| 
 | |||
| 
 | |||
| class Partners(models.Model): | |||
|     """ | |||
|     ResPartners class for add methods and field for generate qr code, | |||
|     Methods: | |||
|         init(self): | |||
|             Initializing res.partners to add sequence | |||
|         create(self, vals): | |||
|             Create method for adding sequence when new partner creating. | |||
|         generate_qr(self): | |||
|             QRcode generating method | |||
|         get_partner_by_qr(self, **args): | |||
|             For getting qr code info of corresponding partner | |||
|     """ | |||
|     _inherit = 'res.partner' | |||
| 
 | |||
|     sequence = fields.Char(string="QR Sequence", readonly=True) | |||
|     qr = fields.Binary(string="QR Code") | |||
| 
 | |||
|     def init(self): | |||
|         """ Initializing res.partners to add sequence """ | |||
|         for record in self.env['res.partner'].search( | |||
|                 [('customer_rank', '=', True)]): | |||
|             name = record.name.replace(" ", "") | |||
|             record.sequence = 'DEF' + name.upper() + str(record.id) | |||
| 
 | |||
|     @api.model | |||
|     def create(self, vals): | |||
|         """ Create method for adding sequence when new partner creating. """ | |||
|         prefix = 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')) | |||
|         prefix = str(prefix) | |||
|         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): | |||
|         """ QR code generating method """ | |||
|         if qrcode and base64: | |||
|             if not self.sequence: | |||
|                 prefix = 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')) | |||
|                 prefix = str(prefix) | |||
|                 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')) | |||
| 
 | |||
|     def get_partner_by_qr(self, **args): | |||
|         """ For getting qr code info of curresponding partner """ | |||
|         return self.env['res.partner'].search([('sequence', '=', self.id), ], | |||
|                                               limit=1).id | |||
| @ -0,0 +1,21 @@ | |||
| <?xml version="1.0" encoding="UTF-8" ?> | |||
| <odoo> | |||
|     <!--  Record for inherit Product form to add sequence and generate qr button  --> | |||
|     <record id="product_form_inherit" model="ir.ui.view"> | |||
|         <field name="name">product.product.form.qr.inherit</field> | |||
|         <field name="model">product.product</field> | |||
|         <field name="inherit_id" ref="product.product_normal_form_view"/> | |||
|         <field name="arch" type="xml"> | |||
|             <div name="button_box" position="inside"> | |||
|                 <button name="generate_qr" type="object" class="btn-box" | |||
|                         icon="fa-qrcode"> | |||
|                     <field name="sequence" invisible="1"/> | |||
|                     Generate QR | |||
|                 </button> | |||
|             </div> | |||
|             <field name="categ_id" position="after"> | |||
|                 <field name="sequence"/> | |||
|             </field> | |||
|         </field> | |||
|     </record> | |||
| </odoo> | |||
| @ -0,0 +1,17 @@ | |||
| <?xml version="1.0" encoding="UTF-8" ?> | |||
| <odoo> | |||
|     <!--  Record for inherit Product template form to add generate qr button  --> | |||
|     <record id="product_template_form_inherit" model="ir.ui.view"> | |||
|         <field name="name">product.template.form.qr.inherit</field> | |||
|         <field name="model">product.template</field> | |||
|         <field name="inherit_id" | |||
|                ref="product.product_template_only_form_view"/> | |||
|         <field name="arch" type="xml"> | |||
|             <div name="button_box" position="inside"> | |||
|                 <button name="generate_qr" type="object" class="btn-box" | |||
|                         icon="fa-qrcode">Generate QR | |||
|                 </button> | |||
|             </div> | |||
|         </field> | |||
|     </record> | |||
| </odoo> | |||
| @ -0,0 +1,41 @@ | |||
| <?xml version="1.0" encoding="UTF-8" ?> | |||
| <odoo> | |||
|     <!--  Record for inherit ResConfigSettings view to add prefix fields in general settings  --> | |||
|     <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="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="col-xs-3 col-md-6 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> | |||
| </odoo> | |||
| @ -0,0 +1,21 @@ | |||
| <?xml version="1.0" encoding="UTF-8" ?> | |||
| <odoo> | |||
|     <!--  Record for inherit Partner form to add sequence and generate qr button  --> | |||
|     <record id="partner_form_inherit" model="ir.ui.view"> | |||
|         <field name="name">res.partner.form.qr.inherit</field> | |||
|         <field name="model">res.partner</field> | |||
|         <field name="inherit_id" ref="base.view_partner_form"/> | |||
|         <field name="arch" type="xml"> | |||
|             <div name="button_box" position="inside"> | |||
|                 <button name="generate_qr" type="object" class="btn-box" | |||
|                         icon="fa-qrcode"> | |||
|                     <field name="sequence" invisible="1"/> | |||
|                     Generate QR | |||
|                 </button> | |||
|             </div> | |||
|             <field name="category_id" position="after"> | |||
|                 <field name="sequence"/> | |||
|             </field> | |||
|         </field> | |||
|     </record> | |||
| </odoo> | |||
| @ -1,105 +0,0 @@ | |||
| <?xml version="1.0" encoding="UTF-8" ?> | |||
| <odoo> | |||
|     <data> | |||
|         <record id="partner_form_inherit" model="ir.ui.view"> | |||
|             <field name="name">res.partner.form.qr.inherit</field> | |||
|             <field name="model">res.partner</field> | |||
|             <field name="inherit_id" ref="base.view_partner_form"/> | |||
|             <field name="arch" type="xml"> | |||
|                 <div name="button_box" position="inside"> | |||
|                     <button name="generate_qr" type="object" class="btn-box" | |||
|                             icon="fa-qrcode"> | |||
|                         <field name="sequence" invisible="1"/> | |||
|                         Generate QR | |||
|                     </button> | |||
|                 </div> | |||
|                 <field name="category_id" position="after"> | |||
|                     <field name="sequence"/> | |||
|                 </field> | |||
|             </field> | |||
|         </record> | |||
|         <record id="product_form_inherit" model="ir.ui.view"> | |||
|             <field name="name">product.product.form.qr.inherit</field> | |||
|             <field name="model">product.product</field> | |||
|             <field name="inherit_id" ref="product.product_normal_form_view"/> | |||
|             <field name="arch" type="xml"> | |||
|                 <div name="button_box" position="inside"> | |||
|                     <button name="generate_qr" type="object" class="btn-box" | |||
|                             icon="fa-qrcode"> | |||
|                         <field name="sequence" invisible="1"/> | |||
|                         Generate QR | |||
|                     </button> | |||
|                 </div> | |||
|                 <field name="categ_id" position="after"> | |||
|                     <field name="sequence"/> | |||
|                 </field> | |||
|             </field> | |||
|         </record> | |||
|         <record id="product_template_form_inherit" model="ir.ui.view"> | |||
|             <field name="name">product.template.form.qr.inherit</field> | |||
|             <field name="model">product.template</field> | |||
|             <field name="inherit_id" | |||
|                    ref="product.product_template_only_form_view"/> | |||
|             <field name="arch" type="xml"> | |||
|                 <div name="button_box" position="inside"> | |||
| 
 | |||
|                     <button name="generate_qr" type="object" class="btn-box" | |||
|                             icon="fa-qrcode">Generate QR | |||
|                     </button> | |||
|                 </div> | |||
|             </field> | |||
|         </record> | |||
|         <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="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="col-xs-3 col-md-6 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> | |||
|     </data> | |||
|     <data noupdate="1"> | |||
|         <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="padding">5</field> | |||
|         </record> | |||
|     </data> | |||
|     <data noupdate="1"> | |||
|         <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="padding">5</field> | |||
|         </record> | |||
|     </data> | |||
| </odoo> | |||
					Loading…
					
					
				
		Reference in new issue