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 -*- # -*- coding: utf-8 -*-
############################################################################## # Copyright (C) 2016-2017 Akretion (http://www.akretion.com)
#
# POS Second EAN13 module for Odoo
# Copyright (C) 2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@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/>.
#
##############################################################################
{ {
'name': 'POS Second EAN13', 'name': 'POS Second EAN13',
'version': '0.1', 'version': '10.0.1.0.0',
'category': 'Point Of Sale', 'category': 'Point Of Sale',
'license': 'AGPL-3', 'license': 'AGPL-3',
'summary': "Add a second EAN13 on products", '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', 'website': 'http://www.akretion.com',
'depends': ['product'], 'depends': ['product'],
'data': ['product_view.xml'], '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 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 --- a/addons/point_of_sale/static/src/js/db.js
+++ b/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){ @@ -155,6 +155,9 @@ var PosDB = core.Class.extend({
if(product.ean13){ if (product.barcode) {
this.product_by_ean13[product.ean13] = product; str += '|' + product.barcode;
} }
+ if(product.second_ean13){ + if (product.second_barcode) {
+ this.product_by_ean13[product.second_ean13] = product; + str += '|' + product.second_barcode;
+ } + }
if(product.default_code){ if (product.default_code) {
this.product_by_reference[product.default_code] = product; 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 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 --- a/addons/point_of_sale/static/src/js/models.js
+++ b/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 @@ -307,7 +307,7 @@ exports.PosModel = Backbone.Model.extend({
},
},{
model: 'product.product', model: 'product.product',
fields: ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'ean13', 'default_code', - fields: ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'barcode', 'default_code',
'to_weight', 'uom_id', 'uos_id', 'uos_coeff', 'mes_type', 'description_sale', 'description', + fields: ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'barcode', 'second_barcode', 'default_code',
+ 'second_ean13', 'to_weight', 'uom_id', 'description_sale', 'description',
'product_tmpl_id'], 'product_tmpl_id','tracking'],
domain: [['sale_ok','=',true],['available_in_pos','=',true]], order: ['sequence','default_code','name'],
context: function(self){ return { pricelist: self.pricelist.id, display_default_code: false }; },

View File

@@ -1,47 +1,31 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # Copyright (C) 2016-2017 Akretion (http://www.akretion.com)
#
# POS Second EAN13 module for Odoo
# Copyright (C) 2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@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/>.
#
##############################################################################
from openerp import models, fields, api, _ from odoo import models, fields, api, _
from openerp.exceptions import ValidationError from odoo.exceptions import ValidationError
from openerp.addons.product.product import check_ean
class ProductProduct(models.Model): class ProductProduct(models.Model):
_inherit = 'product.product' _inherit = 'product.product'
second_ean13 = fields.Char( second_barcode = fields.Char(
string='Second EAN13 Barcode', size=13, copy=False, string='Second Barcode', copy=False, oldname='second_ean13',
help='If the same product is available with two EAN13, you can enter ' help='If the same product is available with two barcodes, you can '
'a second EAN13 in this field') 'enter a second barcode in this field')
@api.multi # TODO
@api.constrains('second_ean13') # 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): def _check_second_ean13(self):
for product in self: for product in self:
if product.second_ean13: if product.second_barcode and not product.barcode:
if not product.ean13:
raise ValidationError(_( raise ValidationError(_(
"You should use the second EAN13 field only when " "You should use the second barcode field only when "
"there is already a value in the main EAN13 field")) "there is already a value in the main barcode field"))
if not check_ean(product.second_ean13):
raise ValidationError(_(
"The second EAN13 barcode is invalid."))

View File

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