mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: reconcile payment with statements by ref and/or folios
This commit is contained in:
@@ -34,40 +34,11 @@ class AccountBankStatement(models.Model):
|
|||||||
)
|
)
|
||||||
super(AccountBankStatement, self).button_post()
|
super(AccountBankStatement, self).button_post()
|
||||||
for line in lines_of_moves_to_post:
|
for line in lines_of_moves_to_post:
|
||||||
folio_ids = line.folio_ids.ids
|
payment_move_line = line._get_payment_move_lines_to_reconcile(line)
|
||||||
if folio_ids:
|
statement_move_line = line.move_id.line_ids.filtered(
|
||||||
to_reconcile_ids = self.env["account.move.line"].search(
|
lambda line: line.account_id.reconcile
|
||||||
[
|
)
|
||||||
("move_id.folio_ids", "in", folio_ids),
|
if payment_move_line and statement_move_line:
|
||||||
("reconciled", "=", False),
|
statement_move_line.account_id = payment_move_line.account_id
|
||||||
"|",
|
lines_to_reconcile = payment_move_line + statement_move_line
|
||||||
(
|
lines_to_reconcile.reconcile()
|
||||||
"account_id",
|
|
||||||
"=",
|
|
||||||
self.journal_id.payment_debit_account_id.id,
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"account_id",
|
|
||||||
"=",
|
|
||||||
self.journal_id.payment_credit_account_id.id,
|
|
||||||
),
|
|
||||||
("journal_id", "=", self.journal_id.id),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
if to_reconcile_ids:
|
|
||||||
statement_move_line = line.move_id.line_ids.filtered(
|
|
||||||
lambda line: line.account_id.reconcile
|
|
||||||
)
|
|
||||||
payment_lines = self.env["account.move.line"].browse(
|
|
||||||
to_reconcile_ids.ids
|
|
||||||
)
|
|
||||||
# We try to reconcile by amount
|
|
||||||
payment_line = False
|
|
||||||
for record in payment_lines:
|
|
||||||
payment_line = (
|
|
||||||
record if abs(record.balance) == line.amount else False
|
|
||||||
)
|
|
||||||
if payment_line and statement_move_line:
|
|
||||||
statement_move_line.account_id = payment_line.account_id
|
|
||||||
lines_to_reconcile = payment_line + statement_move_line
|
|
||||||
lines_to_reconcile.reconcile()
|
|
||||||
|
|||||||
@@ -48,3 +48,33 @@ class AccountBankStatementLine(models.Model):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
return line_vals_list
|
return line_vals_list
|
||||||
|
|
||||||
|
def _get_payment_move_lines_to_reconcile(self):
|
||||||
|
self.ensure_one()
|
||||||
|
payment_move_line = False
|
||||||
|
folio_ids = self.folio_ids and self.folio_ids.ids or False
|
||||||
|
domain = [("move_id.folio_ids", "in", folio_ids)] if folio_ids else []
|
||||||
|
domain.extend(
|
||||||
|
[
|
||||||
|
("move_id.ref", "=", self.payment_ref),
|
||||||
|
("date", "=", self.date),
|
||||||
|
("reconciled", "=", False),
|
||||||
|
"|",
|
||||||
|
(
|
||||||
|
"account_id",
|
||||||
|
"=",
|
||||||
|
self.journal_id.payment_debit_account_id.id,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"account_id",
|
||||||
|
"=",
|
||||||
|
self.journal_id.payment_credit_account_id.id,
|
||||||
|
),
|
||||||
|
("journal_id", "=", self.journal_id.id),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
to_reconcile_move_lines = self.env["account.move.line"].search(domain)
|
||||||
|
# We try to reconcile by amount
|
||||||
|
for record in to_reconcile_move_lines:
|
||||||
|
payment_move_line = record if record.balance == self.amount else False
|
||||||
|
return payment_move_line
|
||||||
|
|||||||
Reference in New Issue
Block a user