<commit_before># -*- coding: utf-8 -*-
# Copyright 2017 <NAME>, Comunitea Servicios Tecnológicos S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, fields, api, _
from odoo.exceptions import AccessError, UserError, ValidationError


DEFAULT_PRE = "843540%"



class ProductTemplate(models.Model):

    _inherit = 'product.template'

    @api.multi
    def asign_barcode(self):
        for template in self:
            template.product_variant_ids.asign_barcode()


class ProductProduct(models.Model):

    _inherit = 'product.product'

    @api.multi
    def write(self, vals):
        # Comprobamos si hay movimientos. No podemos por el tema de Mecalux
        if vals.get('barcode', False):
            for product in self:
                if product.stock_move_ids:
                    raise ValidationError(_("You can change barcode because this product has moves"))
        return super(ProductProduct, self).write(vals)

    def next_barcode(self):
        sequence = self.env.ref('product_ean_generator.seq_product_ean_auto')
        EAN = sequence.next_by_id()
        #
        # sql_last_barcode = "select MAX(left(barcode,12)) from product_product " \
        #                   "where length(barcode)=13 and barcode like '%s'" % DEFAULT_PRE
        #
        # self.env.cr.execute(sql_last_barcode)<commit_msg>[imp] eliminar chech movimientos<commit_after># -*- coding: utf-8 -*-
# Copyright 2017 <NAME>, Comunitea Servicios Tecnológicos S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, fields, api, _
from odoo.exceptions import AccessError, UserError, ValidationError


DEFAULT_PRE = "843540%"



class ProductTemplate(models.Model):

    _inherit = 'product.template'

    @api.multi
    def asign_barcode(self):
        for template in self:
            template.product_variant_ids.asign_barcode()


class ProductProduct(models.Model):

    _inherit = 'product.product'

    @api.multi
    def write(self, vals):
        # Comprobamos si hay movimientos. No podemos por el tema de Mecalux
        if vals.get('barcode', False):
            for product in self:
                if product.stock_move_ids and False:
                    raise ValidationError(_("You can change barcode because this product has moves"))
        return super(ProductProduct, self).write(vals)

    def next_barcode(self):
        sequence = self.env.ref('product_ean_generator.seq_product_ean_auto')
        EAN = sequence.next_by_id()
        #
        # sql_last_barcode = "select MAX(left(barcode,12)) from product_product " \
        #                   "where length(barcode)=13 and barcode like '%s'" % DEFAULT_PRE
        #
        # self.env.cr.execute(sql_last_barcode)
{'fraction_non_alphanumeric': 0.10198915009041591, 'fraction_numerical': 0.012296564195298372, 'mean_word_length': 2.768392370572207, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7581765', 'n_tokens_mistral': 882, 'n_tokens_neox': 827, 'n_words': 206}