diff --git a/pos_second_ean13/__manifest__.py b/pos_second_ean13/__manifest__.py index 78eec67..0912f32 100644 --- a/pos_second_ean13/__manifest__.py +++ b/pos_second_ean13/__manifest__.py @@ -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 -# -# 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 . -# -############################################################################## +# Copyright (C) 2016-2017 Akretion (http://www.akretion.com) +# @author Alexis de Lattre { '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 -# -# 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 . -# -############################################################################## +# Copyright (C) 2016-2017 Akretion (http://www.akretion.com) +# @author Alexis de Lattre -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")) diff --git a/pos_second_ean13/product_view.xml b/pos_second_ean13/product_view.xml index 49d238a..1030ca9 100644 --- a/pos_second_ean13/product_view.xml +++ b/pos_second_ean13/product_view.xml @@ -1,26 +1,23 @@ - - + - usability.product.template.form + pos_second_barcode.product.template.form product.product - - + + - - +