<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

FINANCIAL_TYPE = [
    ('r', u'Account Receivable'),
    ('rr', u'Receipt'),
    ('p', u'Account Payable'),
    ('pp', u'Payment'),
    # ('in', u'Money in'),
    # ('out', u'Recieve'),
    # ('trans', u'Transfer'),
]

FINANCIAL_STATE = [
    ('draft', u'Draft'),
    ('open', u'Open'),
    ('paid', u'Paid'),
    ('cancel', u'Cancel'),
]


class FinancialMove(models.Model):

    _name = 'financial.move'
    _description = 'Financial Move'  # TODO
    _inherit = ['mail.thread']
    _order = "business_due_date desc, " \
             "ref desc, ref_item desc, document_number, id desc"  # TODO:
    _rec_name = 'ref'

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

    @api.multi
    @api.depends('due_date')
    def _compute_business_due_date(self):
        for record in self:
            if record.due_date:
                record.business_due_date = self.env[
                    'resource.calendar'].proximo_dia_util(
                    fields.Date.from_string(record.due_date))

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

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

    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,
    )
    move_type = fields.Selection(
        selection=FINANCIAL_TYPE,
    )
    state = fields.Selection(
        selection=FINANCIAL_STATE,
        string='Status',
        index=True,
        readonly=True,
        default='draft',
        track_visibility='onchange',
        copy=False,
    )
    active = fields.Boolean(
        string=u'Active',
        default=True,
    )
    company_id = fields.Many2one(
        comodel_name='res.company',
        string=u'Company',
        required=True,
    )
    currency_id = fields.Many2one(
        comodel_name='res.currency',
        string='Currency',
        required=True,
    )
    payment_mode = fields.Many2one(
        comodel_name='payment.mode'
    )
    analytic_account_id = fields.Char()  # FIXME .Many2one(
    #
    # )
    account_account_id = fields.Char()  # FIXME .Many2one(
    #
    # )
    partner_id = fields.Many2one(
        comodel_name='res.partner',
        required=True,
    )
    # partner_bank_id = fields.Many2one(
    #     comodel_name='res.partner.bank',
    # )
    # move_type = fields.Char()  # FIXME:
    document_number = fields.Char(
        string=u"Document Nº",
        required=True,
    )
    document_date = fields.Date(
        string=u"Data Emissão",
        required=True,
    )  # FIXME: Data do documento ou
    amount_document = fields.Monetary(
        string=u"Document amount",
        required=True,
    )
    balance = fields.Monetary(
        compute='_compute_balance'
    )
    account = fields.Char()
    historic = fields.One2many(
        comodel_name='financial.move.history',
        inverse_name='financial_move_id',
    )
    due_date = fields.Date(
        string=u"Due date",
        required=True,
    )
    business_due_date = fields.Date(
        string='Business due date',
        compute='_compute_business_due_date',
        store=True,
        index=True,
    )
    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',<commit_msg>[NEW] readonly nos estagios diferentes de draft<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

FINANCIAL_TYPE = [
    ('r', u'Account Receivable'),
    ('rr', u'Receipt'),
    ('p', u'Account Payable'),
    ('pp', u'Payment'),
    # ('in', u'Money in'),
    # ('out', u'Recieve'),
    # ('trans', u'Transfer'),
]

FINANCIAL_STATE = [
    ('draft', u'Draft'),
    ('open', u'Open'),
    ('paid', u'Paid'),
    ('cancel', u'Cancel'),
]


class FinancialMove(models.Model):

    _name = 'financial.move'
    _description = 'Financial Move'  # TODO
    _inherit = ['mail.thread']
    _order = "business_due_date desc, " \
             "ref desc, ref_item desc, document_number, id desc"  # TODO:
    _rec_name = 'ref'

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

    @api.multi
    @api.depends('due_date')
    def _compute_business_due_date(self):
        for record in self:
            if record.due_date:
                record.business_due_date = self.env[
                    'resource.calendar'].proximo_dia_util(
                    fields.Date.from_string(record.due_date))

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

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

    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)]},
    )
    move_type = fields.Selection(
        selection=FINANCIAL_TYPE,
    )
    state = fields.Selection(
        selection=FINANCIAL_STATE,
        string='Status',
        index=True,
        readonly=True,
        default='draft',
        track_visibility='onchange',
        copy=False,
    )
    active = fields.Boolean(
        string=u'Active',
        default=True,
    )
    company_id = fields.Many2one(
        comodel_name='res.company',
        string=u'Company',
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]},
    )
    currency_id = fields.Many2one(
        comodel_name='res.currency',
        string='Currency',
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]},
    )
    payment_mode = fields.Many2one(
        comodel_name='payment.mode'
    )
    analytic_account_id = fields.Char()  # FIXME .Many2one(
    #
    # )
    account_account_id = fields.Char()  # FIXME .Many2one(
    #
    # )
    partner_id = fields.Many2one(
        comodel_name='res.partner',
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]},
    )
    # partner_bank_id = fields.Many2one(
    #     comodel_name='res.partner.bank',
    # )
    # move_type = fields.Char()  # FIXME:
    document_number = fields.Char(
        string=u"Document Nº",
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]},
    )
    document_date = fields.Date(
        string=u"Data Emissão",
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]},
    )  # FIXME: Data do documento ou
    amount_document = fields.Monetary(
        string=u"Document amount",
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]},
    )
    balance = fields.Monetary(
        compute='_compute_balance'
    )
    account = fields.Char()
    historic = fields.One2many(
        comodel_name='financial.move.history',
        inverse_name='financial_move_id',
    )
    due_date = fields.Date(
        string=u"Due date",
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]},
    )
    business_due_date = fields.Date(
        string='Business due date',
        compute='_compute_business_due_date',
        store=True,
        index=True,
    )
    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',
{'fraction_non_alphanumeric': 0.1361728913134704, 'fraction_numerical': 0.003147293327738145, 'mean_word_length': 2.3273996509598605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2223242', 'n_tokens_mistral': 3056, 'n_tokens_neox': 3007, 'n_words': 549}