<commit_before># -*- coding: utf-8 -*-
# Copyright 2017 KMEE
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


class FinancialMove(models.Model):
    _name = 'financial.move'
    _description = 'Financial Move'
    _inherit = ['mail.thread', 'financial.move.model']
    _order = "business_due_date desc, " \
             "ref desc, ref_item desc, document_number, id desc"
    _rec_name = 'ref'

    @api.multi
    @api.depends('ref', 'ref_item')
    def _compute_display_name(self):
        for record in self:
            if record.ref_item:
                record.display_name = record.ref + '/' + record.ref_item
            else:
                record.display_name = record.ref or ''

    @api.model
    def _avaliable_transition(self, old_state, new_state):
        allowed = [
            ('draft', 'open'),
            ('open', 'paid'),
            ('open', 'cancel'),
        ]
        return (old_state, new_state) in allowed

    ref = fields.Char(
        string='Ref',
        required=True,
        copy=False,
        readonly=True,
        states={'draft': [('readonly', False)]},
        index=True,
        default=lambda self: _('New')
    )
    ref_item = fields.Char(
        string=u"ref item",
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]},
    )
    display_name = fields.Char(
        string='Financial Reference',
        compute='_compute_display_name',
    )
    active = fields.Boolean(
        string=u'Active',
        default=True,
        track_visibility='onchange',
    )
    analytic_account_id = fields.Char()  # FIXME .Many2one(
    #
    # )
    account_account_id = fields.Char()  # FIXME .Many2one(
    #
    # )
    balance = fields.Monetary(
        compute='_compute_balance',
        track_visibility='onchange',
    )
    account = fields.Char()
    payment_date = fields.Date()
    credit_debit_date = fields.Date()
    amount_payment = fields.Monetary()
    # percent_interest = fields.Float() #  TODO:
    amount_interest = fields.Monetary()
    # percent_discount = fields.Float() #  TODO:
    amount_discount = fields.Monetary()
    amount_delay_fee = fields.Monetary()
    amount_residual = fields.Monetary()
    expected_date = fields.Date()  # TODO: Data prevista
    storno = fields.Boolean(
        string=u'Storno',
        readonly=True
    )
    printed = fields.Boolean(
        string=u'Printed',
        readonly=True
    )
    sent = fields.Boolean(
        string=u'Sent',
        readonly=True
    )
    regociated = fields.Boolean()
    regociated_id = fields.Many2one(
        comodel_name='financial.move',
    )
    related_regociated_ids = fields.One2many(
        comodel_name='financial.move',
        inverse_name='regociated_id',
    )
    payment_id = fields.Many2one(
        comodel_name='financial.move',
    )
    related_payment_ids = fields.One2many(
        comodel_name='financial.move',
        inverse_name='payment_id',
        readonly=True,
    )
    change_reason = fields.Text(
        string="Change reason",
        track_visibility='onchange',
    )

    move_id = fields.Many2one('account.move', string='Journal Entry',
                              readonly=True, index=True, ondelete='restrict',
                              copy=False,
                              help="Link to the automatically generated "
                                   "Journal Items.")

    account_move_line_id = fields.Many2one(
        comodel_name='account.move.line',
        # compute='_compute_account_move_line_ids',
        store=True
    )
    payment_receivable_ids = fields.One2many(
        comodel_name='account.move.line',
        compute='_compute_payment_receivable_ids',
    )

    @api.multi
    @api.depends('account_move_line_id')
    def _compute_payment_receivable_ids(self):
        for record in self:
            # print "account_move_line_id"
            ids = []
            aml = record.account_move_line_id
            ids.extend([r.debit_move_id.id for r in
                        aml.matched_debit_ids] if
                       aml.credit > 0 else [r.credit_move_id.id for r in
                                            aml.matched_credit_ids])
            record.payment_receivable_ids = ids
            record.payment_receivable_ids |= record.account_move_line_id

    # partner_bank_id = fields.Many2one(
    #     comodel_name='res.partner.bank',
    # )
    # move_type = fields.Char()  # FIXME:

    @api.multi
    def change_state(self, new_state):
        for record in self:
            if record._avaliable_transition(record.state, new_state):<commit_msg>[ADD] Sincronizacao da criacao contabil/financeiro<commit_after># -*- coding: utf-8 -*-
# Copyright 2017 KMEE
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


class FinancialMove(models.Model):
    _name = 'financial.move'
    _description = 'Financial Move'
    _inherit = ['mail.thread', 'financial.move.model']
    _order = "business_due_date desc, " \
             "ref desc, ref_item desc, document_number, id desc"
    _rec_name = 'ref'

    @api.multi
    @api.depends('ref', 'ref_item')
    def _compute_display_name(self):
        for record in self:
            if record.ref_item:
                record.display_name = record.ref + '/' + record.ref_item
            else:
                record.display_name = record.ref or ''

    @api.model
    def _avaliable_transition(self, old_state, new_state):
        allowed = [
            ('draft', 'open'),
            ('open', 'paid'),
            ('open', 'cancel'),
        ]
        return (old_state, new_state) in allowed

    ref = fields.Char(
        string='Ref',
        required=True,
        copy=False,
        readonly=True,
        states={'draft': [('readonly', False)]},
        index=True,
        default=lambda self: _('New')
    )
    ref_item = fields.Char(
        string=u"ref item",
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]},
    )
    display_name = fields.Char(
        string='Financial Reference',
        compute='_compute_display_name',
    )
    active = fields.Boolean(
        string=u'Active',
        default=True,
        track_visibility='onchange',
    )
    analytic_account_id = fields.Char()  # FIXME .Many2one(
    #
    # )
    account_account_id = fields.Char()  # FIXME .Many2one(
    #
    # )
    balance = fields.Monetary(
        compute='_compute_balance',
        track_visibility='onchange',
    )
    account = fields.Char()
    payment_date = fields.Date()
    credit_debit_date = fields.Date()
    amount_payment = fields.Monetary()
    # percent_interest = fields.Float() #  TODO:
    amount_interest = fields.Monetary()
    # percent_discount = fields.Float() #  TODO:
    amount_discount = fields.Monetary()
    amount_delay_fee = fields.Monetary()
    amount_residual = fields.Monetary()
    expected_date = fields.Date()  # TODO: Data prevista
    storno = fields.Boolean(
        string=u'Storno',
        readonly=True
    )
    printed = fields.Boolean(
        string=u'Printed',
        readonly=True
    )
    sent = fields.Boolean(
        string=u'Sent',
        readonly=True
    )
    regociated = fields.Boolean()
    regociated_id = fields.Many2one(
        comodel_name='financial.move',
    )
    related_regociated_ids = fields.One2many(
        comodel_name='financial.move',
        inverse_name='regociated_id',
    )
    payment_id = fields.Many2one(
        comodel_name='financial.move',
    )
    related_payment_ids = fields.One2many(
        comodel_name='financial.move',
        inverse_name='payment_id',
        readonly=True,
    )
    change_reason = fields.Text(
        string="Change reason",
        track_visibility='onchange',
    )

    move_id = fields.Many2one('account.move', string='Journal Entry',
                              readonly=True, index=True, ondelete='restrict',
                              copy=False,
                              help="Link to the automatically generated "
                                   "Journal Items.")

    account_move_line_id = fields.Many2one(
        comodel_name='account.move.line',
        # compute='_compute_account_move_line_ids',
        store=True
    )
    payment_receivable_ids = fields.One2many(
        comodel_name='account.move.line',
        compute='_compute_payment_receivable_ids',
    )

    @api.multi
    @api.depends('account_move_line_id')
    def _compute_payment_receivable_ids(self):
        for record in self:
            ids = []
            aml = record.account_move_line_id
            ids.extend([r.debit_move_id.id for r in
                        aml.matched_debit_ids] if
                       aml.credit > 0 else [r.credit_move_id.id for r in
                                            aml.matched_credit_ids])
            record.payment_receivable_ids = ids
            record.payment_receivable_ids |= record.account_move_line_id

    # partner_bank_id = fields.Many2one(
    #     comodel_name='res.partner.bank',
    # )
    # move_type = fields.Char()  # FIXME:

    @api.multi
    def change_state(self, new_state):
        for record in self:
            if record._avaliable_transition(record.state, new_state):
{'fraction_non_alphanumeric': 0.11172355310578758, 'fraction_numerical': 0.0038159847360610556, 'mean_word_length': 2.1671701913393755, 'pattern_counts': {'":': 0, '<': 3, '<?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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6708293', 'n_tokens_mistral': 2918, 'n_tokens_neox': 2832, 'n_words': 511}