forked from OCA/sale-workflow
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaccount_move.py
More file actions
39 lines (32 loc) · 1.31 KB
/
account_move.py
File metadata and controls
39 lines (32 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Copyright 2022 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class AccountMove(models.Model):
_inherit = "account.move"
def _post(self, soft=True):
# Automatic reconciliation of payment when invoice confirmed.
res = super()._post(soft=soft)
for move in self:
sale_order = move.mapped("line_ids.sale_line_ids.order_id")
if not sale_order:
continue
# Get payment move IDs first
payment_move_ids = sale_order.account_payment_ids.move_id.ids
if not payment_move_ids:
continue
# Domain search (most efficient for large datasets)
advance_payment_lines = self.env["account.move.line"].search(
[
("move_id", "in", payment_move_ids),
(
"account_id.account_type",
"in",
("asset_receivable", "liability_payable"),
),
("reconciled", "=", False),
("parent_state", "=", "posted"),
]
)
for line in advance_payment_lines:
move.js_assign_outstanding_line(line_id=line.id)
return res