Skip to content

Commit

Permalink
Merge branch '12.0' into 12.0-fix_error_nfse_simpliss
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Nov 28, 2019
2 parents 004191b + 45a9a46 commit c45f55d
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 27 deletions.
1 change: 1 addition & 0 deletions br_account_payment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'views/payment_statement.xml',
'security/account_security.xml',
'wizard/payment_cnab_import.xml',
'wizard/payment_move_line.xml'
],
'installable': True,
'application': True,
Expand Down
16 changes: 16 additions & 0 deletions br_account_payment/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,19 @@ def action_register_payment(self):
if self.invoice_id:
vals['context']['default_invoice_ids'] = [self.invoice_id.id]
return vals

@api.multi
def action_register_payment_move_line(self):
dummy, act_id = self.env['ir.model.data'].get_object_reference(
'br_account_payment', 'action_payment_account_move_line'
)
receivable = (self.user_type_id.type == 'receivable')
vals = self.env['ir.actions.act_window'].browse(act_id).read()[0]
vals['context'] = {
'default_amount': self.debit or self.credit,
'default_partner_type': 'customer' if receivable else 'supplier',
'default_partner_id': self.partner_id.id,
'default_communication': self.name,
'default_move_line_id': self.id,
}
return vals
14 changes: 1 addition & 13 deletions br_account_payment/models/account_payment.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# © 2016 Alessandro Fernandes Martini, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

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


class AccountPayment(models.Model):
Expand All @@ -21,17 +20,6 @@ def default_get(self, fields):
'default_amount', rec.get('amount', 0.0))
return rec

def _create_payment_entry(self, amount):
self = self.with_context(move_line_to_reconcile=self.move_line_id)
return super(AccountPayment, self)._create_payment_entry(amount)

def action_validate_invoice_payment(self):
if any(len(record.invoice_ids) > 1 for record in self):
# For multiple invoices, there is account.register.payments wizard
raise UserError(_("This method should only be called\
to process a single invoice's payment."))
return self.post()

@api.depends('partner_id', 'partner_type')
def _compute_open_moves(self):
for item in self:
Expand Down
4 changes: 2 additions & 2 deletions br_account_payment/views/account_invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<field name="inherit_id" ref="br_account.view_br_account_invoice_form"/>
<field name="arch" type="xml">
<tree name="vencimentos" position="inside">
<button name="action_register_payment" type="object" string="PAGAR" groups="account.group_account_invoice" class="btn btn-success btn-xs" />
<button name="action_register_payment_move_line" type="object" string="PAGAR" groups="account.group_account_invoice" class="btn btn-success btn-xs" />
</tree>
<field name="payment_term_id" position="after">
<field name="payment_mode_id" />
Expand All @@ -21,7 +21,7 @@
<field name="inherit_id" ref="br_account.view_br_account_invoice_supplier_form"/>
<field name="arch" type="xml">
<tree name="vencimentos" position="inside">
<button name="action_register_payment" type="object" string="PAGAR" groups="account.group_account_invoice" class="btn btn-success btn-xs" />
<button name="action_register_payment_move_line" type="object" string="PAGAR" groups="account.group_account_invoice" class="btn btn-success btn-xs" />
</tree>
</field>
</record>
Expand Down
9 changes: 0 additions & 9 deletions br_account_payment/views/account_payment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,11 @@
<field name="partner_id"
attrs="{'required': [('payment_type', 'in', ('inbound', 'outbound'))], 'invisible': [('payment_type', 'not in', ('inbound', 'outbound'))], 'readonly': [('state', '!=', 'draft')]}"
context="{'default_is_company': True, 'default_supplier': payment_type == 'outbound', 'default_customer': payment_type == 'inbound'}"/>
<!--<field name="payment_type" widget="radio" attrs="{'readonly': [('state', '!=', 'draft')]}" string="Tipo de Pagamento"/>-->
</xpath>
<xpath expr="//field[@name='payment_date']" position="after">
<field name="journal_id" widget="selection" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
</xpath>

<xpath expr="//label[@for='amount']" position="attributes">
<attribute name="string">Valor do Pagamento</attribute>
</xpath>

<xpath expr="//field[@name='payment_date']" position="attributes">
<attribute name="string">Data de Pagamento</attribute>
</xpath>

</field>
</record>

Expand Down
2 changes: 1 addition & 1 deletion br_account_payment/views/br_account_payment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<field name="date_maturity"/>
<field name="move_id" readonly="1"/>
<field name="reconciled" string="Pago" />
<button name="action_register_payment" type="object" string="PAGAR" groups="account.group_account_invoice" attrs="{'invisible': [('reconciled', '!=', False)]}" class="btn btn-success btn-xs"/>
<button name="action_register_payment_move_line" type="object" string="PAGAR" groups="account.group_account_invoice" attrs="{'invisible': [('reconciled', '!=', False)]}" class="btn btn-success btn-xs"/>
</tree>
</field>
</record>
Expand Down
1 change: 1 addition & 0 deletions br_account_payment/wizard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import payment_cnab_import
from . import payment_move_line
125 changes: 125 additions & 0 deletions br_account_payment/wizard/payment_move_line.py
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()
43 changes: 43 additions & 0 deletions br_account_payment/wizard/payment_move_line.xml
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>
2 changes: 1 addition & 1 deletion br_boleto/views/account_move_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<field name="model">account.move.line</field>
<field name="inherit_id" ref="br_account_payment.view_payments_tree_a_receber" />
<field name="arch" type="xml">
<button name="action_register_payment" position="after">
<button name="action_register_payment_move_line" position="after">
<button name="open_wizard_print_boleto" type="object" string="BOLETO" class="btn btn-success btn-xs"/>
</button>
</field>
Expand Down
2 changes: 1 addition & 1 deletion br_payment_invoice/views/account_move.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<field name="model">account.move.line</field>
<field name="inherit_id" ref="br_account_payment.view_payments_tree_a_receber" />
<field name="arch" type="xml">
<button name="action_register_payment" position="after">
<button name="action_register_payment_move_line" position="after">
<button name="open_wizard_schedule_payment" type="object" string="AGENDAR" class="btn btn-success btn-xs"/>
</button>
</field>
Expand Down

0 comments on commit c45f55d

Please sign in to comment.