[ADD] data_patch_hook: a module to patch data if needed
This commit is contained in:
parent
0d405c1c98
commit
d39f88ebb9
|
|
@ -0,0 +1,29 @@
|
|||
from odoo import api, SUPERUSER_ID
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
def post_init_hook(cr, registry):
|
||||
"""
|
||||
This function serves as the hook to apply data patches and commit changes
|
||||
before raising an intentional error.
|
||||
"""
|
||||
# Example functions to call (define these functions elsewhere in this file)
|
||||
update_due_date_in_transaction_model(cr, registry)
|
||||
|
||||
# Commit the changes
|
||||
cr.commit()
|
||||
|
||||
# Raise an intentional error to prevent module installation
|
||||
raise ValidationError("Intentional error: This module is not designed to be installed.\nData Applied Successfully!")
|
||||
|
||||
def update_due_date_in_transaction_model(cr, registry):
|
||||
"""
|
||||
Recalculate the is_late field for all records after module upgrade.
|
||||
"""
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
|
||||
transaction_models = ['outgoing.transaction', 'internal.transaction', 'incoming.transaction']
|
||||
for transaction_model in transaction_models:
|
||||
model = env[transaction_model]
|
||||
records = model.search([]) # Fetch all records
|
||||
records.compute_due_date() # Trigger computation
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
'name': 'Data Patches with Hook',
|
||||
'version': '1.0',
|
||||
'summary': 'A module to apply data patches using a hook.',
|
||||
'category': 'Tools',
|
||||
'author': 'Expert Co.',
|
||||
'description': """
|
||||
This module apply data patches via hooks.
|
||||
""",
|
||||
'depends': ['base'],
|
||||
'data': [],
|
||||
'installable': True,
|
||||
'application': False,
|
||||
'post_init_hook': 'post_init_hook',
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
|
||||
Loading…
Reference in New Issue