forked from OCA/bank-payment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.py
39 lines (35 loc) · 1.52 KB
/
hooks.py
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 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import SUPERUSER_ID, api
def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
fields_mapping = [
("property_account_receivable_id", "property_stored_account_receivable_id"),
("property_account_payable_id", "property_stored_account_payable_id"),
]
for orig_fname, new_fname in fields_mapping:
orig_model_field = env["ir.model.fields"]._get("res.partner", orig_fname)
new_model_field = env["ir.model.fields"]._get("res.partner", new_fname)
sql = """
UPDATE ir_property
SET name = %s,
fields_id = %s
WHERE fields_id = %s;
"""
cr.execute(sql, (new_fname, new_model_field.id, orig_model_field.id))
def uninstall_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
fields_mapping = [
("property_account_receivable_id", "property_stored_account_receivable_id"),
("property_account_payable_id", "property_stored_account_payable_id"),
]
for orig_fname, new_fname in fields_mapping:
orig_model_field = env["ir.model.fields"]._get("res.partner", orig_fname)
new_model_field = env["ir.model.fields"]._get("res.partner", new_fname)
sql = """
UPDATE ir_property
SET name = %s,
fields_id = %s
WHERE fields_id = %s;
"""
cr.execute(sql, (orig_fname, orig_model_field.id, new_model_field.id))