Skip to content

Commit

Permalink
[NEW] Receivables computed field
Browse files Browse the repository at this point in the history
  • Loading branch information
sadamo committed Apr 21, 2020
1 parent a80a0a8 commit 575fcb4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
28 changes: 23 additions & 5 deletions l10n_br_account_payment_cobranca/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
class AccountInvoice(models.Model):
_inherit = "account.invoice"

@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()

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

active = fields.Boolean(string="Ativo", default=True)

# eval_state_cnab = fields.Selection(
Expand Down Expand Up @@ -121,9 +139,9 @@ def _onchange_payment_term(self):
)

def _remove_payment_order_line(self, _raise=True):
move_line_receivable_id = self.move_line_receivable_id
move_line_receivable_ids = self.move_line_receivable_ids
payment_order_ids = self.env["account.payment.order"].search(
[("payment_line_ids.move_line_id", "in", [move_line_receivable_id.id])]
[("payment_line_ids.move_line_id", "in", [move_line_receivable_ids.id])]
)

if payment_order_ids:
Expand All @@ -143,7 +161,7 @@ def _remove_payment_order_line(self, _raise=True):
p_line_id = self.env["account.payment.line"].search(
[
("order_id", "=", po_id.id),
("move_line_id", "=", move_line_receivable_id.id),
("move_line_id", "=", move_line_receivable_ids.id),
]
)
po_id.payment_line_ids -= p_line_id
Expand Down Expand Up @@ -283,7 +301,7 @@ def _pos_action_move_create(self):
for inv in self:
# inv.transaction_id = sequence
inv._compute_receivables()
for index, interval in enumerate(inv.move_line_receivable_id):
for index, interval in enumerate(inv.move_line_receivable_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 @@ -437,7 +455,7 @@ def register_payment(

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

return res
2 changes: 1 addition & 1 deletion l10n_br_account_payment_cobranca/reports/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#
# if active_model == "account.invoice":
# for invoices in env["account.invoice"].browse(active_ids):
# receivable_ids = invoices.mapped("move_line_receivable_id")
# receivable_ids = invoices.mapped("move_line_receivable_ids")
# if receivable_ids:
# ids_move_lines = receivable_ids
# elif active_model == "account.move.line":
Expand Down

0 comments on commit 575fcb4

Please sign in to comment.