-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '12.0' into 12.0-fix_error_nfse_simpliss
- Loading branch information
Showing
11 changed files
with
192 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# © 2019 Raphael Rodrigues, Trustcode | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models, api, _ | ||
from odoo.exceptions import ValidationError, UserError | ||
|
||
|
||
class PaymentAccountMoveLine(models.TransientModel): | ||
_name = 'payment.account.move.line' | ||
_description = 'Assistente Para Lançamento de Pagamentos' | ||
|
||
company_id = fields.Many2one( | ||
'res.company', related='journal_id.company_id', | ||
string='Exmpresa', readonly=True | ||
) | ||
move_line_id = fields.Many2one( | ||
'account.move.line', readonly=True, string='Conta à Pagar/Receber') | ||
invoice_id = fields.Many2one( | ||
'account.invoice', readonly=True, string='Fatura') | ||
partner_type = fields.Selection( | ||
[('customer', 'Cliente'), ('supplier', 'Fornecedor')], readonly=True) | ||
partner_id = fields.Many2one( | ||
'res.partner', string='Cliente/Fornecedor', readonly=True | ||
) | ||
journal_id = fields.Many2one( | ||
'account.journal', string="Diário", required=True, | ||
domain=[('type', 'in', ('bank', 'cash'))] | ||
) | ||
communication = fields.Char(string='Anotações') | ||
payment_date = fields.Date( | ||
string='Data do Pagamento', | ||
default=fields.Date.context_today, required=True | ||
) | ||
currency_id = fields.Many2one( | ||
'res.currency', string='Moeda', required=True, | ||
default=lambda self: self.env.user.company_id.currency_id | ||
) | ||
amount_residual = fields.Monetary( | ||
string='Saldo', readonly=True, | ||
related='move_line_id.amount_residual' | ||
) | ||
amount = fields.Monetary( | ||
string='Valor do Pagamento', required=True, | ||
) | ||
|
||
@api.model | ||
def default_get(self, fields): | ||
rec = super(PaymentAccountMoveLine, self).default_get(fields) | ||
move_line_id = rec.get('move_line_id', False) | ||
amount = 0 | ||
if not move_line_id: | ||
raise UserError( | ||
_("Não foi selecionada nenhuma linha de cobrança.")) | ||
move_line = self.env['account.move.line'].browse(move_line_id) | ||
if move_line[0].amount_residual: | ||
amount = move_line[0].amount_residual if \ | ||
rec['partner_type'] == 'customer' else \ | ||
move_line[0].amount_residual * -1 | ||
if move_line[0].invoice_id: | ||
invoice = move_line[0].invoice_id | ||
else: | ||
raise (_("A linha de cobrança selecionada não possui nenhuma" | ||
"fatura relacionada.")) | ||
rec.update({ | ||
'amount': amount, | ||
'invoice_id': invoice.id, | ||
}) | ||
return rec | ||
|
||
@api.onchange('amount') | ||
def validate_amount_payment(self): | ||
""" | ||
Method used to validate the payment amount to be recorded | ||
:return: | ||
""" | ||
real_amount_residual = self.amount_residual if \ | ||
self.partner_type == 'customer' else \ | ||
self.amount_residual * -1 | ||
if self.amount > real_amount_residual: | ||
raise ValidationError(_( | ||
'O valor do pagamento não pode ser maior ' | ||
'que o valor da parcela.')) | ||
|
||
@api.constrains('payment_date') | ||
def validate_payment_date(self): | ||
""" | ||
Method used to validate payment date | ||
:return: | ||
""" | ||
move_line_date = self.move_line_id.date | ||
if self.payment_date < move_line_date: | ||
raise ValidationError(_('A data do pagamento não pode ser inferior' | ||
' a data da parcela.')) | ||
|
||
def _get_payment_vals(self): | ||
""" | ||
Method responsible for generating payment record amounts | ||
""" | ||
payment_type = 'inbound' if self.move_line_id.debit else 'outbound' | ||
payment_methods = \ | ||
payment_type == 'inbound' and \ | ||
self.journal_id.inbound_payment_method_ids or \ | ||
self.journal_id.outbound_payment_method_ids | ||
payment_method_id = payment_methods and payment_methods[0] or False | ||
return { | ||
'partner_id': self.partner_id.id, | ||
'move_line_id': self.move_line_id.id, | ||
'invoice_ids': [(6, 0, [self.invoice_id.id])], | ||
'journal_id': self.journal_id.id, | ||
'communication': self.communication, | ||
'amount': self.amount, | ||
'payment_date': self.payment_date, | ||
'payment_type': payment_type, | ||
'payment_method_id': payment_method_id.id, | ||
'currency_id': self.currency_id.id, | ||
} | ||
|
||
def action_confirm_payment(self): | ||
""" | ||
Method responsible for creating the payment | ||
""" | ||
payment = self.env['account.payment'] | ||
vals = self._get_payment_vals() | ||
pay = payment.create(vals) | ||
pay.post() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="view_payment_account_move_line_form" model="ir.ui.view"> | ||
<field name="name">wizard.payment.account.move.line</field> | ||
<field name="model">payment.account.move.line</field> | ||
<field name="arch" type="xml"> | ||
<form string="Payment Move Line"> | ||
<sheet> | ||
<group> | ||
<group> | ||
<field name="company_id" invisible="1"/> | ||
<field name="currency_id" invisible="1"/> | ||
<field name="partner_type" invisible="1"/> | ||
<field name="amount_residual" invisible="1"/> | ||
<field name="partner_id"/> | ||
<field name="move_line_id"/> | ||
<field name="invoice_id"/> | ||
<field name="journal_id"/> | ||
<field name="amount"/> | ||
<field name="payment_date"/> | ||
<field name="communication"/> | ||
</group> | ||
</group> | ||
</sheet> | ||
<footer> | ||
<button string="Confirmar Pagamento" name="action_confirm_payment" type="object" class="btn-primary"/> | ||
<button string="Cancelar" class="btn-secondary" special="cancel"/> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="action_payment_account_move_line" model="ir.actions.act_window"> | ||
<field name="name">Register Payment Move Line</field> | ||
<field name="res_model">payment.account.move.line</field> | ||
<field name="view_type">form</field> | ||
<field name="view_mode">form</field> | ||
<field name="view_id" ref="view_payment_account_move_line_form"/> | ||
<field name="target">new</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters