diff --git a/customer_product_qrcode/__init__.py b/customer_product_qrcode/__init__.py
index fbaeb400a..f7949667d 100755
--- a/customer_product_qrcode/__init__.py
+++ b/customer_product_qrcode/__init__.py
@@ -20,10 +20,4 @@
#############################################################################
from . import models
from . import report
-from odoo import api, SUPERUSER_ID
-def _set_qr(cr):
- env = api.Environment(cr, SUPERUSER_ID, {})
- for record in env['product.product'].search([]):
- name = record.name.replace(" ", "")
- record.sequence = 'DEF' + name.upper()+str(record.id)
- record.generate_qr()
+
diff --git a/customer_product_qrcode/__manifest__.py b/customer_product_qrcode/__manifest__.py
index f90fa1fa0..b714fa5a7 100755
--- a/customer_product_qrcode/__manifest__.py
+++ b/customer_product_qrcode/__manifest__.py
@@ -29,21 +29,21 @@
'company': 'Cybrosys Techno Solutions',
'maintainer': 'Cybrosys Techno Solutions',
'website': 'https://www.cybrosys.com',
- 'depends': ['base', 'sale', 'stock'],
+ 'depends': ['base', 'sale_management', 'stock'],
'data': [
'data/sequence.xml',
+ 'data/ir_actions_server_data.xml',
'views/res_config_settings_view.xml',
'views/res_partner_view.xml',
'views/product_product_view.xml',
'views/product_template_view.xml',
- 'report/customer_product_qrcode_template.xml',
'report/paperformat.xml',
'report/report_action.xml',
+ 'report/customer_product_qrcode_template.xml',
],
'images': ['static/description/banner.jpg'],
'license': 'LGPL-3',
'installable': True,
'auto_install': False,
'application': False,
- 'post_init_hook': '_set_qr'
}
diff --git a/customer_product_qrcode/data/ir_actions_server_data.xml b/customer_product_qrcode/data/ir_actions_server_data.xml
new file mode 100644
index 000000000..a12873878
--- /dev/null
+++ b/customer_product_qrcode/data/ir_actions_server_data.xml
@@ -0,0 +1,28 @@
+
+
+
+ Generate Qr
+
+
+ form,list
+ code
+
+ for record in records:
+ if not record.sequence:
+ action = record.generate_sequence()
+
+
+
+
+ Generate Qr
+
+
+ form,list
+ code
+
+ for record in records:
+ if not record.sequence:
+ action = record.generate_sequence()
+
+
+
\ No newline at end of file
diff --git a/customer_product_qrcode/models/product_product.py b/customer_product_qrcode/models/product_product.py
index 9d18c0748..6bcdb5480 100644
--- a/customer_product_qrcode/models/product_product.py
+++ b/customer_product_qrcode/models/product_product.py
@@ -66,20 +66,22 @@ class ProductProduct(models.Model):
vals.update({'qr': qr_image})
return super().create(vals)
- @api.depends('sequence')
+ def generate_sequence(self):
+ 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 '/'
+
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(
- '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 '/'
+ self.generate_sequence()
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
@@ -94,7 +96,7 @@ class ProductProduct(models.Model):
qr_image = base64.b64encode(temp.getvalue())
self.write({'qr': qr_image})
return self.env.ref(
- 'customer_product_qrcode.print_qr2').report_action(self, data={
+ 'customer_product_qrcode.print_qr1').report_action(self, data={
'data': self.id, 'type': 'prod'})
else:
raise UserError(
diff --git a/customer_product_qrcode/models/product_template.py b/customer_product_qrcode/models/product_template.py
index 4d880d36b..1a86f76d0 100644
--- a/customer_product_qrcode/models/product_template.py
+++ b/customer_product_qrcode/models/product_template.py
@@ -19,6 +19,7 @@
#
#############################################################################
from odoo import models
+from odoo.exceptions import UserError
class ProductTemplate(models.Model):
@@ -26,12 +27,13 @@ class ProductTemplate(models.Model):
related product variants."""
_inherit = 'product.template'
+ def generate_sequence(self):
+ for rec in self.product_variant_ids:
+ if not rec.sequence:
+ rec.generate_sequence()
+
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), ])
- 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'})
+ for rec in self.product_variant_ids:
+ return rec.generate_qr()
\ No newline at end of file
diff --git a/customer_product_qrcode/models/res_partner.py b/customer_product_qrcode/models/res_partner.py
index 673f5dd3b..1058a05fc 100644
--- a/customer_product_qrcode/models/res_partner.py
+++ b/customer_product_qrcode/models/res_partner.py
@@ -66,20 +66,22 @@ class ResPartners(models.Model):
""" this fn is to write vals"""
return super().write(vals)
- @api.depends('sequence')
+ def generate_sequence(self):
+ 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 '/'
+
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(
- '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 '/'
+ self.generate_sequence()
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
diff --git a/customer_product_qrcode/report/report_action.xml b/customer_product_qrcode/report/report_action.xml
old mode 100755
new mode 100644
index 53cbc4f59..c62a58652
--- a/customer_product_qrcode/report/report_action.xml
+++ b/customer_product_qrcode/report/report_action.xml
@@ -25,17 +25,5 @@
report
-
-
- QR code
- product.template
- qweb-pdf
- customer_product_qrcode.customer_qr_template
- customer_product_qrcode.customer_qr_template
-
- '%s - Badge' % object.name
-
- report
-