<commit_before># Copyright (C) 2009  <NAME> - Akretion <<EMAIL>>
# Copyright (C) 2014  KMEE - www.kmee.com.br
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import api, fields, models

from ..constants.fiscal import DOCUMENT_TYPE


class DocumentType(models.Model):
    _name = 'l10n_br_fiscal.document.type'
    _description = 'Fiscal Document Type'
    _inheirt = 'l10n_br_fiscal.data.abstract'

    code = fields.Char(
        size=8,
    )

    name = fields.Char(
        size=128,
    )

    electronic = fields.Boolean(
        string='Is Electronic?',
    )

    type = fields.Selection(
        selection=DOCUMENT_TYPE,
        string='Document Type',
        required=True
    )

    document_serie_ids = fields.One2many(
        comodel_name='l10n_br_fiscal.document.serie',
        inverse_name='document_type_id',
        string='Document Series',
    )

    def _get_default_document_serie(self, company):
        """Overwrite this method in a custom fiscal document
        like l10n_br_nfe, l10n_br_nfse and etc, to return a
        especific fiscal document serie"""
        document_serie = self.env['l10n_br_fiscal.document.serie']
        return document_serie.search([
            ('active', '=', True),
            ('company_id', '=', company.id)])

    @api.multi
    def get_document_serie(self, company, fiscal_operation):
        self.ensure_one()
        serie = self.env['l10n_br_fiscal.document.serie']
        if fiscal_operation:
            # Get document serie from fiscal operation
            serie = fiscal_operation.get_document_serie(
                company, fiscal_operation)

        if not serie:
            # Get try defini default serie
            serie = self._get_default_document_serie(company)

        return serie<commit_msg>[FIX] get_document_serie method<commit_after># Copyright (C) 2009  <NAME> - Akretion <<EMAIL>>
# Copyright (C) 2014  KMEE - www.kmee.com.br
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import api, fields, models

from ..constants.fiscal import DOCUMENT_TYPE


class DocumentType(models.Model):
    _name = 'l10n_br_fiscal.document.type'
    _description = 'Fiscal Document Type'
    _inheirt = 'l10n_br_fiscal.data.abstract'

    code = fields.Char(
        size=8,
    )

    name = fields.Char(
        size=128,
    )

    electronic = fields.Boolean(
        string='Is Electronic?',
    )

    type = fields.Selection(
        selection=DOCUMENT_TYPE,
        string='Document Type',
        required=True
    )

    document_serie_ids = fields.One2many(
        comodel_name='l10n_br_fiscal.document.serie',
        inverse_name='document_type_id',
        string='Document Series',
    )

    def _get_default_document_serie(self, company):
        """Overwrite this method in a custom fiscal document
        modules like l10n_br_nfe, l10n_br_nfse and etc, to
        return a especific fiscal document serie"""
        document_serie = self.env['l10n_br_fiscal.document.serie']
        return document_serie.search([
            ('active', '=', True),
            ('company_id', '=', company.id),
            ('document_type_id', '=', self.id)], limit=1)

    @api.multi
    def get_document_serie(self, company, fiscal_operation):
        self.ensure_one()
        serie = self.env['l10n_br_fiscal.document.serie']
        if fiscal_operation:
            # Get document serie from fiscal operation
            serie = fiscal_operation.get_document_serie(
                company, self)

        if not serie:
            # Get try defini default serie
            serie = self._get_default_document_serie(company)

        return serie
{'fraction_non_alphanumeric': 0.10236220472440945, 'fraction_numerical': 0.01656258484930763, 'mean_word_length': 2.5525554484088717, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4808545', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1168, 'n_words': 247}