Skip to content

Commit

Permalink
[MOV] Implementation made in l10n_br_account module.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbcosta committed Feb 26, 2021
1 parent 0d97906 commit 575a9a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
33 changes: 7 additions & 26 deletions l10n_br_account_payment_order/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
class AccountInvoice(models.Model):
_inherit = 'account.invoice'

move_line_receivable_ids = fields.Many2many(
comodel_name='account.move.line',
string='Receivables',
store=True,
compute='_compute_receivables',
)

eval_payment_mode_instructions = fields.Text(
string='Instruções de Cobrança do Modo de Pagamento',
related='payment_mode_id.instructions',
Expand All @@ -35,18 +28,6 @@ class AccountInvoice(models.Model):
# index=True,
# )

@api.multi
@api.depends('state', 'move_id.line_ids', 'move_id.line_ids.account_id')
def _compute_receivables(self):
for record in self:
lines = self.env['account.move.line']
for line in record.move_id.line_ids:
if (line.account_id.id == record.account_id.id
and line.account_id.internal_type in ('receivable',
'payable')):
lines |= line
record.move_line_receivable_ids = lines.sorted()

@api.onchange('payment_mode_id')
def _onchange_payment_mode_id(self):
tax_analytic_tag_id = self.env.ref(
Expand Down Expand Up @@ -92,11 +73,11 @@ def _remove_payment_order_line(self, _raise=True):
:param _raise:
:return:
"""
move_line_receivable_ids = self.move_line_receivable_ids
financial_move_line_ids = self.financial_move_line_ids
payment_order_ids = self.env['account.payment.order']

payment_order_ids |= self.env['account.payment.order'].search([
('payment_line_ids.move_line_id', 'in', move_line_receivable_ids.ids),
('payment_line_ids.move_line_id', 'in', financial_move_line_ids.ids),
])

if payment_order_ids:
Expand All @@ -113,7 +94,7 @@ def _remove_payment_order_line(self, _raise=True):

for po_id in draft_cancel_payment_order_ids:
p_line_id = self.env['account.payment.line']
for line in move_line_receivable_ids:
for line in financial_move_line_ids:
p_line_id |= self.env['account.payment.line'].search([
('order_id', '=', po_id.id),
('move_line_id', '=', line.id)])
Expand All @@ -140,20 +121,20 @@ def get_invoice_fiscal_number(self):
@api.multi
def _pos_action_move_create(self):
for inv in self:
# TODO - apesar do campo move_line_receivable_ids ser do tipo
# TODO - apesar do campo financial_move_line_ids ser do tipo
# compute esta sendo preciso chamar o metodo porque as vezes
# ocorre da linha vir vazia o que impede de entrar no FOR
# abaixo causando o não preenchimento de dados usados no Boleto,
# isso deve ser melhor investigado
if not inv.payment_mode_id:
continue
inv._compute_receivables()
inv._compute_financial()

# Verifica se gera Ordem de Pagamento
if not inv.payment_mode_id.payment_order_ok:
continue

for index, interval in enumerate(inv.move_line_receivable_ids):
for index, interval in enumerate(inv.financial_move_line_ids):
inv_number = inv.get_invoice_fiscal_number().split('/')[-1].zfill(8)
numero_documento = inv_number + '/' + str(index + 1).zfill(2)

Expand Down Expand Up @@ -420,7 +401,7 @@ def register_payment(

for inv in self:
inv._compute_receivables()
receivable_id = inv.move_line_receivable_ids
receivable_id = inv.financial_move_line_ids
receivable_id.residual = inv.residual

return res
5 changes: 0 additions & 5 deletions l10n_br_account_payment_order/views/account_invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
<button name="create_account_payment_line" position="attributes">
<attribute name="invisible">1</attribute>
</button>
<notebook position="inside">
<page string="Vencimentos" name="vencimentos">
<field name="move_line_receivable_ids"/>
</page>
</notebook>
</field>
</record>

Expand Down

0 comments on commit 575a9a4

Please sign in to comment.