From 540d7cf82c2ed85058433f774c0fcbae37e9917c Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 13 Jan 2016 11:50:51 +0100 Subject: [PATCH] Add module second_ean13 --- pos_second_ean13/__init__.py | 3 ++ pos_second_ean13/__openerp__.py | 43 ++++++++++++++++++++++++++++ pos_second_ean13/product.py | 47 +++++++++++++++++++++++++++++++ pos_second_ean13/product_view.xml | 26 +++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 pos_second_ean13/__init__.py create mode 100644 pos_second_ean13/__openerp__.py create mode 100644 pos_second_ean13/product.py create mode 100644 pos_second_ean13/product_view.xml diff --git a/pos_second_ean13/__init__.py b/pos_second_ean13/__init__.py new file mode 100644 index 0000000..d7d7308 --- /dev/null +++ b/pos_second_ean13/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import product diff --git a/pos_second_ean13/__openerp__.py b/pos_second_ean13/__openerp__.py new file mode 100644 index 0000000..3666363 --- /dev/null +++ b/pos_second_ean13/__openerp__.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# POS Second EAN13 module for Odoo +# Copyright (C) 2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + + +{ + 'name': 'POS Second EAN13', + 'version': '0.1', + 'category': 'Point Of Sale', + 'license': 'AGPL-3', + 'summary': "Add a second EAN13 on products", + 'description': """ +POS Second EAN13 +================ + +This module adds a second EAN13 field on products. This feature has been asked by librairies that often have the same book available from 2 different sources with different EAN13 (to keep things simple, I didn't want to handle N EAN13 ; a second EAN13 was enough for most cases). This module also provides a patch to apply on the javascript of the official *point_of_sale* module. + +This module has been written by Alexis de Lattre from Akretion . + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['product'], + 'data': ['product_view.xml'], + 'installable': True, +} diff --git a/pos_second_ean13/product.py b/pos_second_ean13/product.py new file mode 100644 index 0000000..ad6dd1b --- /dev/null +++ b/pos_second_ean13/product.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# POS Second EAN13 module for Odoo +# Copyright (C) 2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + +from openerp import models, fields, api, _ +from openerp.exceptions import ValidationError +from openerp.addons.product.product import check_ean + + +class ProductProduct(models.Model): + _inherit = 'product.product' + + second_ean13 = fields.Char( + string='Second EAN13 Barcode', size=13, + help='If the same product is available with two EAN13, you can enter ' + 'a second EAN13 in this field') + + @api.multi + @api.constrains('second_ean13') + 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.")) diff --git a/pos_second_ean13/product_view.xml b/pos_second_ean13/product_view.xml new file mode 100644 index 0000000..49d238a --- /dev/null +++ b/pos_second_ean13/product_view.xml @@ -0,0 +1,26 @@ + + + + + + + + + + usability.product.template.form + product.product + + + + + + + + + + +