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

import datetime

from openerp import models, fields, api, _
from openerp.exceptions import Warning as UserError

TYPE = [
    ('input', u'Entrada'),
    ('output', u'Saída'),
]

PRODUCT_FISCAL_TYPE = [
    ('service', u'Serviço'),
]

PRODUCT_FISCAL_TYPE_DEFAULT = PRODUCT_FISCAL_TYPE[0][0]


class L10nBrAccountCce(models.Model):
    _name = 'l10n_br_account.invoice.cce'
    _description = u'Carta de Correção no Sefaz'

    # TODO nome de campos devem ser em ingles
    invoice_id = fields.Many2one('account.invoice', 'Fatura')
    motivo = fields.Text('Motivo', readonly=True, required=True)
    sequencia = fields.Char(
        'Sequencia', help=u"Indica a sequência da carta de correcão")
    cce_document_event_ids = fields.One2many(
        'l10n_br_account.document_event', 'document_event_ids', u'Eventos')


class L10nBrAccountInvoiceCancel(models.Model):
    _name = 'l10n_br_account.invoice.cancel'
    _description = u'Cancelar Documento Eletrônico no Sefaz'

    invoice_id = fields.Many2one('account.invoice', 'Fatura')
    justificative = fields.Char(string='Justificativa', size=255,
                                readonly=True, required=True)
    cancel_document_event_ids = fields.One2many(
        'l10n_br_account.document_event', 'cancel_document_event_id',
        u'Eventos')

    def _check_justificative(self, cr, uid, ids):
        for invalid in self.browse(cr, uid, ids):
            if len(invalid.justificative) < 15:
                return False
        return True

    _constraints = [(
        _check_justificative,
        'Justificativa deve ter tamanho minimo de 15 caracteres.',
        ['justificative'])]


class L10nBrDocumentEvent(models.Model):
    _name = 'l10n_br_account.document_event'

    type = fields.Selection(
        [('-1', u'Exception'),
         ('0', u'Envio Lote'),
         ('1', u'Consulta Recibo'),
         ('2', u'Cancelamento'),
         ('3', u'Inutilização'),
         ('4', u'Consulta NFE'),
         ('5', u'Consulta Situação'),
         ('6', u'Consulta Cadastro'),
         ('7', u'DPEC Recepção'),
         ('8', u'DPEC Consulta'),
         ('9', u'Recepção Evento'),
         ('10', u'Download'),
         ('11', u'Consulta Destinadas'),
         ('12', u'Distribuição DFe'),
         ('13', u'Manifestação'), ], 'Serviço')
    response = fields.Char(u'Descrição', size=64, readonly=True)
    company_id = fields.Many2one(
        'res.company', 'Empresa', readonly=True,
        states={'draft': [('readonly', False)]})
    origin = fields.Char(
        'Documento de Origem', size=64,
        readonly=True, states={'draft': [('readonly', False)]},
        help="Reference of the document that produced event.")
    file_sent = fields.Char('Envio', readonly=True)
    file_returned = fields.Char('Retorno', readonly=True)
    status = fields.Char(u'Código', readonly=True)
    message = fields.Char('Mensagem', readonly=True)
    create_date = fields.Datetime(u'Data Criação', readonly=True)
    write_date = fields.Datetime(u'Data Alteração', readonly=True)
    end_date = fields.Datetime(u'Data Finalização', readonly=True)
    state = fields.Selection(
        [('draft', 'Rascunho'), ('send', 'Enviado'),
         ('wait', 'Aguardando Retorno'), ('done', 'Recebido Retorno')],
        'Status', select=True, readonly=True, default='draft')
    document_event_ids = fields.Many2one(
        'account.invoice', 'Documentos')
    cancel_document_event_id = fields.Many2one(
        'l10n_br_account.invoice.cancel', 'Cancelamento')
    invalid_number_document_event_id = fields.Many2one(
        'l10n_br_account.invoice.invalid.number', u'Inutilização')

    _order = 'write_date desc'

    @api.multi
    def set_done(self):
        self.write({'state': 'done', 'end_date': datetime.datetime.now()})<commit_msg>[FIX] Adicionado display_name em l10n_br_account.invoice.cancel, l10n_br_account.invoice.cce e l10n_br_account.document_event [FIX] Ajuste nos labels dos campos<commit_after># -*- coding: utf-8 -*-
# Copyright (C) 2009 - TODAY <NAME> - Akretion                           #
# Copyright (C) 2014  KMEE - www.kmee.com.br
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

import datetime

from openerp import models, fields, api, _
from openerp.exceptions import Warning as UserError

TYPE = [
    ('input', u'Entrada'),
    ('output', u'Saída'),
]

PRODUCT_FISCAL_TYPE = [
    ('service', u'Serviço'),
]

PRODUCT_FISCAL_TYPE_DEFAULT = PRODUCT_FISCAL_TYPE[0][0]


class L10nBrAccountCce(models.Model):
    _name = 'l10n_br_account.invoice.cce'
    _description = u'Carta de Correção no Sefaz'

    # TODO nome de campos devem ser em ingles
    invoice_id = fields.Many2one('account.invoice', 'Fatura')
    motivo = fields.Text('Motivo', readonly=True, required=True)
    sequencia = fields.Char(
        u'Sequência', help=u"Indica a sequência da carta de correcão")
    cce_document_event_ids = fields.One2many(
        'l10n_br_account.document_event', 'document_event_ids', u'Eventos')

    display_name = fields.Char(
        string='Name', compute='_compute_display_name',
    )

    @api.multi
    @api.depends('invoice_id.internal_number', 'invoice_id.partner_id.name')
    def _compute_display_name(self):
        self.ensure_one()
        names = ['Fatura', self.invoice_id.internal_number,
                 self.invoice_id.partner_id.name]
        self.display_name = ' / '.join(filter(None, names))


class L10nBrAccountInvoiceCancel(models.Model):
    _name = 'l10n_br_account.invoice.cancel'
    _description = u'Documento Eletrônico no Sefaz'

    invoice_id = fields.Many2one('account.invoice', 'Fatura')
    justificative = fields.Char(string='Justificativa', size=255,
                                readonly=True, required=True)
    cancel_document_event_ids = fields.One2many(
        'l10n_br_account.document_event', 'cancel_document_event_id',
        u'Eventos')

    display_name = fields.Char(
        string='Nome', compute='_compute_display_name',
    )

    @api.multi
    @api.depends('invoice_id.internal_number', 'invoice_id.partner_id.name')
    def _compute_display_name(self):
        self.ensure_one()
        names = ['Fatura', self.invoice_id.internal_number,
                 self.invoice_id.partner_id.name]
        self.display_name = ' / '.join(filter(None, names))

    def _check_justificative(self, cr, uid, ids):
        for invalid in self.browse(cr, uid, ids):
            if len(invalid.justificative) < 15:
                return False
        return True

    _constraints = [(
        _check_justificative,
        u'Justificativa deve ter tamanho mínimo de 15 caracteres.',
        ['justificative'])]


class L10nBrDocumentEvent(models.Model):
    _name = 'l10n_br_account.document_event'

    type = fields.Selection(
        [('-1', u'Exception'),
         ('0', u'Envio Lote'),
         ('1', u'Consulta Recibo'),
         ('2', u'Cancelamento'),
         ('3', u'Inutilização'),
         ('4', u'Consulta NFE'),
         ('5', u'Consulta Situação'),
         ('6', u'Consulta Cadastro'),
         ('7', u'DPEC Recepção'),
         ('8', u'DPEC Consulta'),
         ('9', u'Recepção Evento'),
         ('10', u'Download'),
         ('11', u'Consulta Destinadas'),
         ('12', u'Distribuição DFe'),
         ('13', u'Manifestação'), ], 'Serviço')
    response = fields.Char(u'Descrição', size=64, readonly=True)
    company_id = fields.Many2one(
        'res.company', 'Empresa', readonly=True,
        states={'draft': [('readonly', False)]})
    origin = fields.Char(
        'Documento de Origem', size=64,
        readonly=True, states={'draft': [('readonly', False)]},
        help="Referência ao documento que gerou o evento.")
    file_sent = fields.Char('Envio', readonly=True)
    file_returned = fields.Char('Retorno', readonly=True)
    status = fields.Char(u'Código', readonly=True)
    message = fields.Char('Mensagem', readonly=True)
    create_date = fields.Datetime(u'Data Criação', readonly=True)
    write_date = fields.Datetime(u'Data Alteração', readonly=True)
    end_date = fields.Datetime(u'Data Finalização', readonly=True)
    state = fields.Selection(
        [('draft', 'Rascunho'), ('send', 'Enviado'),
         ('wait', 'Aguardando Retorno'), ('done', 'Recebido Retorno')],
        'Status', select=True, readonly=True, default='draft')
    document_event_ids = fields.Many2one(
        'account.invoice', 'Documentos')
    cancel_document_event_id = fields.Many2one(
        'l10n_br_account.invoice.cancel', 'Cancelamento')
    invalid_number_document_event_id = fields.Many2one(
        'l10n_br_account.invoice.invalid.number', u'Inutilização')
    display_name = fields.Char(string='Nome', compute='_compute_display_name')

    _order = 'write_date desc'

    @api.multi
    @api.depends('company_id.name', 'origin')
    def _compute_display_name(self):
        self.ensure_one()
        names = ['Evento', self.company_id.name, self.origin]
        self.display_name = ' / '.join(filter(None, names))

    @api.multi
    def set_done(self):
        self.write({'state': 'done', 'end_date': datetime.datetime.now()})
{'fraction_non_alphanumeric': 0.14241353463968304, 'fraction_numerical': 0.016061676839061997, 'mean_word_length': 3.2396731729459827, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3507773', 'n_tokens_mistral': 3234, 'n_tokens_neox': 3116, 'n_words': 605}