<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


class FinancialPayreceive(models.TransientModel):

    _name = 'financial.pay_receive'
    _inherit = ['account.abstract.payment']

    payment_type = fields.Selection(
        required=False,
    )
    payment_method_id = fields.Many2one(
        required=False,
    )
    ref = fields.Char()
    date_payment = fields.Date(
        required=True,
        default=fields.Date.context_today
    )
    date_credit_debit = fields.Date(
        readonly=True,
        # TODO: compute bussiness date
    )
    amount_discount = fields.Monetary(
        string=u'Discount',
    )
    amount_interest = fields.Monetary(
        string=u'Interest',
        readonly=True,
    )
    journal_id = fields.Many2one(
        required=False,
    )
    bank_id = fields.Many2one(
        'res.partner.bank',
        string=u'Bank Account',
    )

    @api.model
    def default_get(self, vals):
        res = super(FinancialPayreceive, self).default_get(vals)
        active_id = self.env.context.get('active_id')
        if (self.env.context.get('active_model') == 'financial.move' and
                active_id):
            fm = self.env['financial.move'].browse(active_id)
            res['currency_id'] = fm.currency_id.id
            res['amount'] = fm.amount
            res['company_id'] = fm.company_id.id
        return res

    @api.multi
    def doit(self):
        for wizard in self:
            active_id = self._context['active_id']
            account_financial = self.env['financial.move']

            financial_to_pay = account_financial.browse(active_id)

            if financial_to_pay.financial_type == 'p':
                financial_type = 'pp'
            else:
                financial_type = 'rr'

            values = account_financial._prepare_financial_move(
                bank_id=wizard.bank_id.id,
                company_id=wizard.company_id.id,
                currency_id=wizard.currency_id.id,
                financial_type=financial_type,
                partner_id=financial_to_pay.partner_id.id,
                date=wizard.date_payment,
                document_number=financial_to_pay.document_number,
                date_maturity=financial_to_pay.date_maturity,
                amount=wizard.amount,
                account_id=financial_to_pay.account_id.id,
                financial_payment_id=active_id,
            )
            financial = account_financial.create(values)
            financial.action_confirm()
<commit_msg>[ADD] Bank account number proposal on pay/receive wizard<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


class FinancialPayreceive(models.TransientModel):

    _name = 'financial.pay_receive'
    _inherit = ['account.abstract.payment']

    payment_type = fields.Selection(
        required=False,
    )
    payment_method_id = fields.Many2one(
        required=False,
    )
    ref = fields.Char()
    date_payment = fields.Date(
        required=True,
        default=fields.Date.context_today
    )
    date_credit_debit = fields.Date(
        readonly=True,
        # TODO: compute bussiness date
    )
    amount_discount = fields.Monetary(
        string=u'Discount',
    )
    amount_interest = fields.Monetary(
        string=u'Interest',
        readonly=True,
    )
    journal_id = fields.Many2one(
        required=False,
    )
    bank_id = fields.Many2one(
        'res.partner.bank',
        string=u'Bank Account',
        required=True,
    )

    @api.model
    def default_get(self, vals):
        res = super(FinancialPayreceive, self).default_get(vals)
        active_id = self.env.context.get('active_id')
        if (self.env.context.get('active_model') == 'financial.move' and
                active_id):
            fm = self.env['financial.move'].browse(active_id)
            res['currency_id'] = fm.currency_id.id
            res['amount'] = fm.amount
            res['company_id'] = fm.company_id.id
            res['bank_id'] = fm.bank_id.id
        return res

    @api.multi
    def doit(self):
        for wizard in self:
            active_id = self._context['active_id']
            account_financial = self.env['financial.move']

            financial_to_pay = account_financial.browse(active_id)

            if financial_to_pay.financial_type == 'p':
                financial_type = 'pp'
            else:
                financial_type = 'rr'

            values = account_financial._prepare_financial_move(
                bank_id=wizard.bank_id.id,
                company_id=wizard.company_id.id,
                currency_id=wizard.currency_id.id,
                financial_type=financial_type,
                partner_id=financial_to_pay.partner_id.id,
                date=wizard.date_payment,
                document_number=financial_to_pay.document_number,
                date_maturity=financial_to_pay.date_maturity,
                amount=wizard.amount,
                account_id=financial_to_pay.account_id.id,
                financial_payment_id=active_id,
            )
            financial = account_financial.create(values)
            financial.action_confirm()
{'fraction_non_alphanumeric': 0.09992542878448919, 'fraction_numerical': 0.0037285607755406414, 'mean_word_length': 2.1047453703703702, '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': '4141310', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1607, 'n_words': 246}