Browse Source

[ADD] Initial Commit

pull/104/head
Sreejith P 7 years ago
parent
commit
5e23369dc6
  1. 3
      customer_product_qrcode/__init__.py
  2. 46
      customer_product_qrcode/__manifest__.py
  3. 6
      customer_product_qrcode/doc/RELEASE_NOTES.md
  4. 2
      customer_product_qrcode/models/__init__.py
  5. 157
      customer_product_qrcode/models/models.py
  6. 30
      customer_product_qrcode/readme.rst
  7. 2
      customer_product_qrcode/report/__init__.py
  8. 17
      customer_product_qrcode/report/paperformat.xml
  9. 20
      customer_product_qrcode/report/parser.py
  10. 35
      customer_product_qrcode/report/report.xml
  11. 48
      customer_product_qrcode/report/template.xml
  12. BIN
      customer_product_qrcode/static/description/banner.jpg
  13. BIN
      customer_product_qrcode/static/description/cybro-service.png
  14. BIN
      customer_product_qrcode/static/description/cybro_logo.png
  15. BIN
      customer_product_qrcode/static/description/icon.png
  16. BIN
      customer_product_qrcode/static/description/image1.jpg
  17. BIN
      customer_product_qrcode/static/description/image2.jpg
  18. BIN
      customer_product_qrcode/static/description/image3.jpg
  19. BIN
      customer_product_qrcode/static/description/image4.png
  20. 110
      customer_product_qrcode/static/description/index.html
  21. 90
      customer_product_qrcode/views/view.xml

3
customer_product_qrcode/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models
from . import report

46
customer_product_qrcode/__manifest__.py

@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2018-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
# 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 <https://www.gnu.org/licenses/>.
#
##############################################################################
{
'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',
}

6
customer_product_qrcode/doc/RELEASE_NOTES.md

@ -0,0 +1,6 @@
## Module <customer_product_qrcode>
#### 22.10.2018
#### Version 11.0.1.0.0
##### ADD
- Initial commit for Customer and Product QR Module

2
customer_product_qrcode/models/__init__.py

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import models

157
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)

30
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 <https://www.cybrosys.com>
Maintainer
----------
This module is maintained by Cybrosys Technologies.
For support and more information, please visit https://www.cybrosys.com.

2
customer_product_qrcode/report/__init__.py

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import parser

17
customer_product_qrcode/report/paperformat.xml

@ -0,0 +1,17 @@
<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>
</odoo>

20
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,
}

35
customer_product_qrcode/report/report.xml

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<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="Product 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="Customer 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"
menu="False"
/>
<record id="customer_product_qrcode.print_qr" model="ir.actions.report">
<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>
</data>
</odoo>

48
customer_product_qrcode/report/template.xml

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data>
<template id="customer_qr_template">
<t t-foreach="data" t-as="records">
<t t-foreach="records" t-as="record">
<t t-call="web.html_container">
<t t-call="web.internal_layout">
<style>
table{
border:1px solid black !important;
height:370px;
width:370px;
}
tr{
border:1px solid black !important;
}
td{
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><img t-att-src="'data:image/png;base64,%s' % to_text(record.qr)"
style="height:280px;width:280px;float:center;"/><br/>
<span t-esc="record.sequence" style="float:center;"/>
</center>
</td>
</tr>
</table>
</center>
</div>
</t>
</t>
</t>
</t>
</template>
</data>
</odoo>

BIN
customer_product_qrcode/static/description/banner.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 421 KiB

BIN
customer_product_qrcode/static/description/cybro-service.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

BIN
customer_product_qrcode/static/description/cybro_logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
customer_product_qrcode/static/description/icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
customer_product_qrcode/static/description/image1.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

BIN
customer_product_qrcode/static/description/image2.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
customer_product_qrcode/static/description/image3.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
customer_product_qrcode/static/description/image4.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

110
customer_product_qrcode/static/description/index.html

@ -0,0 +1,110 @@
<section class="oe_container">
<div class="oe_row oe_spaced">
<h2 class="oe_slogan">Customer and Product QR Code Generator</h2>
<h3 class="oe_slogan">Generate Unique QR Codes for Customers and Products</h3>
<h4 class="oe_slogan"><a href="https://www.cybrosys.com">Cybrosys Technologies</a> </h4>
</div>
<div class="oe_row oe_spaced">
<div>
<p style="text-align:left;font-size:18px;">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.</p>
<strong style="text-align:left;font-size:16px;">Features:</strong>
<ul style="text-align:left;font-size:16px;">
<li>Unique QR code for products and customers.</li>
<li>Enables to configure a word prefix to QR code for unique identification.</li>
<li>QR code for individual product variants.</li>
<li>QR code for whole product template variants.</li>
</ul>
</div>
</div>
<div class="oe_row oe_spaced">
<div class="oe_span6">
<p class='oe_mt32' style="text-align:left;font-size:16px;">
Set the product and customer prefixes from General Settings Menu.
Set a Unique and Denotable Prefix to Your Customers.
</p>
</div>
<div class="oe_span6">
<div class="oe_demo oe_picture oe_screenshot">
<img src="image4.png">
</div>
</div>
</div>
<div class="oe_row oe_spaced">
<div class="oe_span6">
<div class="oe_demo oe_picture oe_screenshot">
<img src="image1.jpg">
</div>
</div>
<div class="oe_span6">
<p class='oe_mt32' style="text-align:left;font-size:16px;">
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.
</p>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<div class="oe_span6">
<p class='oe_mt32' style="text-align:left;font-size:16px;">
Set the product and customer prefixes from General Settings Menu.
Set a Unique and Denotable Prefix to Your Customers.
</p>
</div>
<div class="oe_span6">
<div class="oe_demo oe_picture oe_screenshot">
<img src="image2.jpg">
</div>
</div>
</div>
</section>
<section>
<div class="oe_row oe_spaced">
<div class="oe_span6">
<div class="oe_demo oe_picture oe_screenshot">
<img src="image3.jpg">
</div>
</div>
<div class="oe_span6">
<p class='oe_mt32' style="text-align:left;font-size:16px;">
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.
</p>
</div>
</div>
<div class="oe_row oe_spaced">
<div class="oe_span12">
<p class='oe_mt32'>
</p>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<h2 class="oe_slogan" style="margin-top:20px;" >Need Any Help?</h2>
<div class="oe_slogan" style="margin-top:10px !important;">
<div>
<a class="btn btn-primary btn-lg mt8"
style="color: #FFFFFF !important;border-radius: 0;" href="http://www.cybrosys.com"><i
class="fa fa-envelope"></i> Email </a> <a
class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;border-radius: 0;"
href="http://www.cybrosys.com/contact/"><i
class="fa fa-phone"></i> Contact Us </a> <a
class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;border-radius: 0;"
href="http://www.cybrosys.com/odoo-customization-and-installation/"><i
class="fa fa-check-square"></i> Request Customization </a>
</div>
<br>
<img src="cybro_logo.png" style="width: 190px; margin-bottom: 20px;" class="center-block">
<div>
<a href="https://twitter.com/cybrosys" target="_blank"><i class="fa fa-2x fa-twitter" style="color:white;background: #00a0d1;width:35px;"></i></a></td>
<a href="https://www.linkedin.com/company/cybrosys-technologies-pvt-ltd" target="_blank"><i class="fa fa-2x fa-linkedin" style="color:white;background: #31a3d6;width:35px;padding-left: 3px;"></i></a></td>
<a href="https://www.facebook.com/cybrosystechnologies" target="_blank"><i class="fa fa-2x fa-facebook" style="color:white;background: #3b5998;width:35px;padding-left: 8px;"></i></a></td>
<a href="https://plus.google.com/106641282743045431892/about" target="_blank"><i class="fa fa-2x fa-google-plus" style="color:white;background: #c53c2c;width:35px;padding-left: 3px;"></i></a></td>
<a href="https://in.pinterest.com/cybrosys" target="_blank"><i class="fa fa-2x fa-pinterest" style="color:white;background: #ac0f18;width:35px;padding-left: 3px;"></i></a></td>
</div>
</div>
</section>

90
customer_product_qrcode/views/view.xml

@ -0,0 +1,90 @@
<?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">
<xpath expr="//button[@name='toggle_active']" position="before">
<button name="generate_qr" type="object" class="btn-box" icon="fa-qrcode"><field name="sequence" invisible="1"/> Generate QR</button>
</xpath>
<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">
<xpath expr="//button[@name='toggle_active']" position="before">
<button name="generate_qr" type="object" class="btn-box" icon="fa-qrcode"><field name="sequence" invisible="1"/> Generate QR</button>
</xpath>
<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">
<xpath expr="//button[@name='toggle_active']" position="before">
<button name="generate_qr" type="object" class="btn-box" icon="fa-qrcode">Generate QR</button>
</xpath>
</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.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[hasclass('settings')]" position="inside">
<div class="app_settings_block" data-string="General Settings" string="General Settings" data-key="general_settings">
<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"/>
<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>
</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…
Cancel
Save