<commit_before># -*- coding: utf-8 -*-
# Copyright (C) 2017 - <NAME> - KMEE INFORMATICA
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, fields, models


# HARD_IMPOSTO = 30
#
# class AccountTax(models.Model):
#     _inherit = 'account.tax'

    # @api.model
    # def _unit_compute(
    #         self, taxes, price_unit, product=None, partner=None, quantity=0):
    #     data = super(AccountTax, self)._unit_compute(
    #         taxes, price_unit, product, partner, quantity)
    #     for dict in data:
    #         if 'id' in dict:
    #             tax = self.browse(dict['id'])
    #             if tax:
    #                 # FIXME: Chamar os roteiros contabeis e determinar a conta
    #                 dict.update({
    #                     'account_counterpart_id': HARD_IMPOSTO,
    #                 })
    #     return data


class AccountInvoice(models.Model):
    _inherit = 'account.invoice'

    def define_account(self, move_line):
        amt = self.env['account.move.template']
        am = self.env['account.account']
        if move_line[2].tax_amount == 0:  # definir linha receita
            # definir parâmetros search
            amt = amt.search([('type', '=', 'receipt')])
            if move_line[2].debit:
                am = amt.debit_account_id or move_line[2].partner_id.\
                    property_account_receivable
            else:
                am = amt.credit_account_id or move_line[2].product_id.\
                    property_account_income

        if False:  # definir linha imposto
            amt = amt.search([]) #definir parâmetros search

        return am

    def finalize_invoice_move_lines(self, move_lines):
        move_lines = super(AccountInvoice, self).finalize_invoice_move_lines(
            move_lines)
        lines = list(move_lines)
        for move in lines:
            partida = move[2]
            aux_debit = partida['debit']
            partida['debit'] = partida['credit']
            partida['credit'] = aux_debit
            partida['account_id'] = self.define_account(move)
            # FIXME: Ele considera apenas os lançamentos duplicados, mas no
            # caso de receita, tanto lançamento original quanto duplicado mudam
            # vide docs
            move_lines.append([0, 0, partida])
        return move_lines<commit_msg>[FIX] contas a serem lançadas<commit_after># -*- coding: utf-8 -*-
# Copyright (C) 2017 - <NAME> - KMEE INFORMATICA
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, fields, models


class AccountInvoice(models.Model):
    _inherit = 'account.invoice'

    def define_account(self, move_line):
        amt = self.env['account.move.template']
        if move_line[2].tax_amount == 0:  # definir linha receita
            # definir parâmetros search
            amt = amt.search([('type', '=', 'receipt')])
            if move_line[2].debit:
                am = amt.debit_account_id
            else:
                am = amt.credit_account_id

        if False:  # definir linha impostopr
            amt = amt.search([]) #definir parâmetros search
            am = amt.debit_account_id

        return am or move_line['account_id']

    def finalize_invoice_move_lines(self, move_lines):
        move_lines = super(AccountInvoice, self).finalize_invoice_move_lines(
            move_lines)
        lines = list(move_lines)
        for move in lines:
            partida = move[2]
            move[2]['account_id'] = self.define_account(move[2])
            partida['debit'] = move[2]['credit']
            partida['credit'] = move[2]['debit']
            partida['account_id'] = self.define_account(partida)
            # FIXME: Ele considera apenas os lançamentos duplicados, mas no
            # caso de receita, tanto lançamento original quanto duplicado mudam
            # vide docs
            move_lines.append([0, 0, partida])
        return move_lines
{'fraction_non_alphanumeric': 0.1070528967254408, 'fraction_numerical': 0.009319899244332493, 'mean_word_length': 2.090272373540856, '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': '4736506', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1210, 'n_words': 278}