mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: matching autoreconcile festures: amount and partner
This commit is contained in:
@@ -48,9 +48,16 @@ class AccountBankStatement(models.Model):
|
|||||||
statement_move_line = line.move_id.line_ids.filtered(
|
statement_move_line = line.move_id.line_ids.filtered(
|
||||||
lambda line: line.account_id.reconcile
|
lambda line: line.account_id.reconcile
|
||||||
)
|
)
|
||||||
payment_line = self.env["account.move.line"].browse(
|
payment_lines = self.env["account.move.line"].browse(
|
||||||
to_reconcile_ids.ids
|
to_reconcile_ids.ids
|
||||||
)[0]
|
)[0]
|
||||||
|
# We try to reconcile by amount
|
||||||
|
for record in payment_lines:
|
||||||
|
payment_line = (
|
||||||
|
record if abs(record.balance) == line.amount else False
|
||||||
|
)
|
||||||
|
if not payment_line:
|
||||||
|
payment_line = payment_lines[0]
|
||||||
if payment_line and statement_move_line:
|
if payment_line and statement_move_line:
|
||||||
statement_move_line.account_id = payment_line.account_id
|
statement_move_line.account_id = payment_line.account_id
|
||||||
lines_to_reconcile = payment_line + statement_move_line
|
lines_to_reconcile = payment_line + statement_move_line
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# Copyright 2017 Dario Lodeiros
|
# Copyright 2017 Dario Lodeiros
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
|
import itertools as it
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
@@ -186,15 +187,33 @@ class AccountMove(models.Model):
|
|||||||
lambda line: line.account_id.user_type_id.type
|
lambda line: line.account_id.user_type_id.type
|
||||||
in ("receivable", "payable")
|
in ("receivable", "payable")
|
||||||
)
|
)
|
||||||
to_reconcile = (
|
to_propose = (
|
||||||
self.env["account.move"]
|
self.env["account.move"]
|
||||||
.browse(list(current_amounts.keys()))
|
.browse(list(current_amounts.keys()))
|
||||||
.line_ids.filtered(
|
.line_ids.filtered(
|
||||||
lambda line: line.account_id == pay_term_lines.account_id
|
lambda line: line.account_id == pay_term_lines.account_id
|
||||||
and line.folio_ids in move.folio_ids
|
and line.folio_ids in move.folio_ids
|
||||||
|
and (
|
||||||
|
line.move_id.partner_id == move.partner_id
|
||||||
|
or not line.move_id.partner_id
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(pay_term_lines + to_reconcile).reconcile()
|
to_reconcile = self.match_pays_by_amount(
|
||||||
|
payments=to_propose, invoice=move
|
||||||
|
)
|
||||||
|
if to_reconcile:
|
||||||
|
(pay_term_lines + to_reconcile).reconcile()
|
||||||
|
# Set partner in payment
|
||||||
|
for record in to_reconcile:
|
||||||
|
if record.payment_id and not record.payment_id.partner_id:
|
||||||
|
record.payment_id.partner_id = move.partner_id
|
||||||
|
if (
|
||||||
|
record.statement_line_id
|
||||||
|
and not record.statement_line_id.partner_id
|
||||||
|
):
|
||||||
|
record.statement_line_id.partner_id = move.partner_id
|
||||||
|
return True
|
||||||
|
|
||||||
def _post(self, soft=True):
|
def _post(self, soft=True):
|
||||||
"""
|
"""
|
||||||
@@ -203,3 +222,17 @@ class AccountMove(models.Model):
|
|||||||
res = super(AccountMove, self)._post(soft)
|
res = super(AccountMove, self)._post(soft)
|
||||||
self._autoreconcile_folio_payments()
|
self._autoreconcile_folio_payments()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def match_pays_by_amount(self, payments, invoice):
|
||||||
|
"""
|
||||||
|
Match payments by amount
|
||||||
|
"""
|
||||||
|
for i in range(len(payments)):
|
||||||
|
combinations = list(it.combinations(payments, i + 1))
|
||||||
|
for combi in combinations:
|
||||||
|
# TODO: compare with currency differences
|
||||||
|
if sum(abs(item.balance) for item in combi) == invoice.amount_residual:
|
||||||
|
return payments.filtered(
|
||||||
|
lambda p: p.id in [item.id for item in combi]
|
||||||
|
)
|
||||||
|
return []
|
||||||
|
|||||||
Reference in New Issue
Block a user