Create module account_payment_mode_default_account

This commit is contained in:
Akim Juillerat
2022-06-30 10:53:04 +02:00
parent 31d375aa93
commit dc18da16da
15 changed files with 405 additions and 0 deletions

View File

@@ -0,0 +1,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))