Port module pos_second_ean13 (still needs some improvements, but it works)

This commit is contained in:
Alexis de Lattre
2017-09-14 19:54:08 +02:00
parent bb849c0228
commit a32d091d83
4 changed files with 63 additions and 89 deletions

View File

@@ -1,29 +1,11 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# POS Second EAN13 module for Odoo
# Copyright (C) 2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright (C) 2016-2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
{
'name': 'POS Second EAN13',
'version': '0.1',
'version': '10.0.1.0.0',
'category': 'Point Of Sale',
'license': 'AGPL-3',
'summary': "Add a second EAN13 on products",
@@ -41,5 +23,5 @@ This module has been written by Alexis de Lattre from Akretion <alexis.delattre@
'website': 'http://www.akretion.com',
'depends': ['product'],
'data': ['product_view.xml'],
'installable': False,
'installable': True,
}

View File

@@ -1,26 +1,37 @@
diff --git a/addons/point_of_sale/static/src/js/db.js b/addons/point_of_sale/static/src/js/db.js
index 819c21f..317eda9 100644
index c2b3fad..abb64c3 100644
--- a/addons/point_of_sale/static/src/js/db.js
+++ b/addons/point_of_sale/static/src/js/db.js
@@ -188,6 +188,9 @@ function openerp_pos_db(instance, module){
if(product.ean13){
this.product_by_ean13[product.ean13] = product;
}
+ if(product.second_ean13){
+ this.product_by_ean13[product.second_ean13] = product;
+ }
if(product.default_code){
this.product_by_reference[product.default_code] = product;
}
@@ -155,6 +155,9 @@ var PosDB = core.Class.extend({
if (product.barcode) {
str += '|' + product.barcode;
}
+ if (product.second_barcode) {
+ str += '|' + product.second_barcode;
+ }
if (product.default_code) {
str += '|' + product.default_code;
}
@@ -206,6 +209,9 @@ var PosDB = core.Class.extend({
if(product.barcode){
this.product_by_barcode[product.barcode] = product;
}
+ if(product.second_barcode){
+ this.product_by_barcode[product.second_barcode] = product;
+ }
}
},
_partner_search_string: function(partner){
diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js
index 0bd1b99..86e8b2f 100644
index 84f033b..f4abc8d 100644
--- a/addons/point_of_sale/static/src/js/models.js
+++ b/addons/point_of_sale/static/src/js/models.js
@@ -282,6 +282,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
model: 'product.product',
fields: ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'ean13', 'default_code',
'to_weight', 'uom_id', 'uos_id', 'uos_coeff', 'mes_type', 'description_sale', 'description',
+ 'second_ean13',
'product_tmpl_id'],
domain: [['sale_ok','=',true],['available_in_pos','=',true]],
context: function(self){ return { pricelist: self.pricelist.id, display_default_code: false }; },
@@ -307,7 +307,7 @@ exports.PosModel = Backbone.Model.extend({
},
},{
model: 'product.product',
- fields: ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'barcode', 'default_code',
+ fields: ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'barcode', 'second_barcode', 'default_code',
'to_weight', 'uom_id', 'description_sale', 'description',
'product_tmpl_id','tracking'],
order: ['sequence','default_code','name'],

View File

@@ -1,47 +1,31 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# POS Second EAN13 module for Odoo
# Copyright (C) 2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright (C) 2016-2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
from openerp import models, fields, api, _
from openerp.exceptions import ValidationError
from openerp.addons.product.product import check_ean
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class ProductProduct(models.Model):
_inherit = 'product.product'
second_ean13 = fields.Char(
string='Second EAN13 Barcode', size=13, copy=False,
help='If the same product is available with two EAN13, you can enter '
'a second EAN13 in this field')
second_barcode = fields.Char(
string='Second Barcode', copy=False, oldname='second_ean13',
help='If the same product is available with two barcodes, you can '
'enter a second barcode in this field')
@api.multi
@api.constrains('second_ean13')
# TODO
# The constrain below is "stupid" because you can have the same
# value in 'barcode' field of product A and second_barcode of product B
_sql_constraints = [(
'second_barcode_unique',
'unique(second_barcode)',
'This barcode already exists!')]
@api.constrains('second_barcode')
def _check_second_ean13(self):
for product in self:
if product.second_ean13:
if not product.ean13:
raise ValidationError(_(
"You should use the second EAN13 field only when "
"there is already a value in the main EAN13 field"))
if not check_ean(product.second_ean13):
raise ValidationError(_(
"The second EAN13 barcode is invalid."))
if product.second_barcode and not product.barcode:
raise ValidationError(_(
"You should use the second barcode field only when "
"there is already a value in the main barcode field"))

View File

@@ -1,26 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
Copyright (C) 2016-2017 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
-->
<openerp>
<data>
<odoo>
<record id="product_normal_form_view" model="ir.ui.view">
<field name="name">usability.product.template.form</field>
<field name="name">pos_second_barcode.product.template.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<field name="ean13" position="after">
<field name="second_ean13"/>
<field name="barcode" position="after">
<field name="second_barcode"/>
</field>
</field>
</record>
</data>
</openerp>
</odoo>