forked from OCA/hr-expense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.py
19 lines (16 loc) · 813 Bytes
/
hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Copyright 2019 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import SUPERUSER_ID, api
def post_init_hook(cr, registry):
"""Trying to fill the source expense sheet in payments"""
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
sheets = env["hr.expense.sheet"].search([("payment_mode", "=", "own_account")])
for sheet in sheets:
amls = sheet.account_move_id.mapped("line_ids")
reconcile = amls.mapped("full_reconcile_id")
aml_payment = reconcile.mapped("reconciled_line_ids").filtered(
lambda r: r not in amls
)
payment = aml_payment.mapped("payment_id")
payment.write({"expense_sheet_ids": sheet.ids})