Port module pos_second_ean13 (still needs some improvements, but it works)
This commit is contained in:
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user