<commit_before># -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in module root
# directory
##############################################################################
from openerp import models, fields, api
import logging
_logger = logging.getLogger(__name__)


class account_voucher_receiptbook(models.Model):

    _name = 'account.voucher.receiptbook'
    _description = 'Account Voucher Receiptbook'
    _order = 'sequence asc'

    def init(self, cr):
        """
        Esto es para instalar si teniamos account_voucher_receipt y antes de
        desinstalar este ultimo para no perder algunos datos
        """
        _logger.info(
            "Update data ids to 'l10n_ar_account_voucher'")

        data_ids = [
            'sequence_customer_receipt_1',
            'sequence_supplier_receipt_1',
            'customer_receiptbook_1',
            'supplier_receiptbook_1',
            'customer_receiptbook_2',
            'supplier_receiptbook_2',
            ]

        cr.execute(
            """UPDATE ir_model_data set module='l10n_ar_account_voucher' where
            module='account_voucher_receipt' and name in %s""" % (
                str(tuple(data_ids))))

        _logger.info(
            "Updating fields external id for receiptbook "
            "so you can uninstall this module'")
        field_prefix = 'field_account_voucher_receiptbook_'
        fields_sufixs = [
            'sequence', 'name', 'type', 'sequence_type', 'sequence_id',
            'company_id', 'manual_prefix', 'padding', 'active',
            'document_class_id']
        fields_with_prefix = []
        for field in fields_sufixs:
            fields_with_prefix.append("%s%s" % (field_prefix, field))

        _logger.info("Moving fields of account_voucher_receipt' if installed")

        cr.execute(
            """UPDATE ir_model_data set module='l10n_ar_account_voucher' where
            module='account_voucher_receipt' and name in %s""" % (
                str(tuple(fields_with_prefix))))

    sequence = fields.Integer(
        'Sequence',
        help="Used to order the receiptbooks",
        default=10,
        )
    name = fields.Char(
        'Name',
        size=64,
        required=True,
        )
    type = fields.Selection(
        [('receipt', 'Receipt'), ('payment', 'Payment')],
        string='Type',
        required=True,
        )
    sequence_type = fields.Selection(
        [('automatic', 'Automatic'), ('manual', 'Manual')],
        string='Sequence Type',
        readonly=False,
        default='automatic',
        )
    sequence_id = fields.Many2one(
        'ir.sequence',
        'Entry Sequence',
        help="This field contains the information related to the numbering\
        of the receipt entries of this receiptbook.",
        copy=False,
        )
    company_id = fields.Many2one(
        'res.company',
        'Company',
        required=True,
        default=lambda self: self.env[
            'res.company']._company_default_get('account.voucher.receiptbook')
        )
    manual_prefix = fields.Char(
        'Prefix',
        required=True,
        # TODO rename field to prefix
        )
    padding = fields.Integer(
        'Number Padding',
        help="automatically adds some '0' on the left of the 'Number' to get\
        the required padding size."
        )
    active = fields.Boolean(
        'Active',
        default=True,
        )
    document_class_id = fields.Many2one(
        'afip.document_class',
        'Document Class',
        required=True,
        )

    @api.model
    def create(self, vals):
        sequence_type = vals.get(
            'sequence_type',
            self._context.get('default_sequence_type', False))
        voucher_type = vals.get(
            'type',
            self._context.get('default_type', False))
        manual_prefix = vals.get(
            'manual_prefix',
            self._context.get('default_manual_prefix', False))
        company_id = vals.get(
            'company_id',
            self._context.get('default_company_id', False))

        if (
                sequence_type == 'automatic' and
                not vals.get('sequence_id', False) and
                company_id and voucher_type):
            seq_vals = {
                'name': vals['name'],
                'implementation': 'no_gap',
                'prefix': manual_prefix,
                'padding': 8,
                'number_increment': 1
            }
            sequence = self.env['ir.sequence'].sudo().create(seq_vals)
            vals.update({
                'sequence_id': sequence.id
                })
        return super(account_voucher_receiptbook, self).create(vals)
<commit_msg>IMP del init on l10 account voucher<commit_after># -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in module root
# directory
##############################################################################
from openerp import models, fields, api
import logging
_logger = logging.getLogger(__name__)


class account_voucher_receiptbook(models.Model):

    _name = 'account.voucher.receiptbook'
    _description = 'Account Voucher Receiptbook'
    _order = 'sequence asc'

    sequence = fields.Integer(
        'Sequence',
        help="Used to order the receiptbooks",
        default=10,
        )
    name = fields.Char(
        'Name',
        size=64,
        required=True,
        )
    type = fields.Selection(
        [('receipt', 'Receipt'), ('payment', 'Payment')],
        string='Type',
        required=True,
        )
    sequence_type = fields.Selection(
        [('automatic', 'Automatic'), ('manual', 'Manual')],
        string='Sequence Type',
        readonly=False,
        default='automatic',
        )
    sequence_id = fields.Many2one(
        'ir.sequence',
        'Entry Sequence',
        help="This field contains the information related to the numbering\
        of the receipt entries of this receiptbook.",
        copy=False,
        )
    company_id = fields.Many2one(
        'res.company',
        'Company',
        required=True,
        default=lambda self: self.env[
            'res.company']._company_default_get('account.voucher.receiptbook')
        )
    manual_prefix = fields.Char(
        'Prefix',
        required=True,
        # TODO rename field to prefix
        )
    padding = fields.Integer(
        'Number Padding',
        help="automatically adds some '0' on the left of the 'Number' to get\
        the required padding size."
        )
    active = fields.Boolean(
        'Active',
        default=True,
        )
    document_class_id = fields.Many2one(
        'afip.document_class',
        'Document Class',
        required=True,
        )

    @api.model
    def create(self, vals):
        sequence_type = vals.get(
            'sequence_type',
            self._context.get('default_sequence_type', False))
        voucher_type = vals.get(
            'type',
            self._context.get('default_type', False))
        manual_prefix = vals.get(
            'manual_prefix',
            self._context.get('default_manual_prefix', False))
        company_id = vals.get(
            'company_id',
            self._context.get('default_company_id', False))

        if (
                sequence_type == 'automatic' and
                not vals.get('sequence_id', False) and
                company_id and voucher_type):
            seq_vals = {
                'name': vals['name'],
                'implementation': 'no_gap',
                'prefix': manual_prefix,
                'padding': 8,
                'number_increment': 1
            }
            sequence = self.env['ir.sequence'].sudo().create(seq_vals)
            vals.update({
                'sequence_id': sequence.id
                })
        return super(account_voucher_receiptbook, self).create(vals)

{'fraction_non_alphanumeric': 0.14294562120649076, 'fraction_numerical': 0.004459308807134894, 'mean_word_length': 2.082856051928217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4938497', 'n_tokens_mistral': 2309, 'n_tokens_neox': 2188, 'n_words': 488}