diff --git a/odex30_base/data_patch_hook/__init__.py b/odex30_base/data_patch_hook/__init__.py new file mode 100644 index 0000000..8ba9ea9 --- /dev/null +++ b/odex30_base/data_patch_hook/__init__.py @@ -0,0 +1,24 @@ +from odoo.exceptions import ValidationError + +def post_init_hook(env): + + + update_due_date_in_transaction_model(env) + + env.cr.commit() + + + raise ValidationError("Intentional error: This module is not designed to be installed.\nData Applied Successfully!") + +def update_due_date_in_transaction_model(env): + + transaction_models = ['outgoing.transaction', 'internal.transaction', 'incoming.transaction'] + for transaction_model in transaction_models: + if transaction_model in env.registry: + model = env[transaction_model] + records = model.search([]) + if records: + records.compute_due_date() + else: + print(f"Model '{transaction_model}' not found in registry. Skipping patch.") + diff --git a/odex30_base/data_patch_hook/__manifest__.py b/odex30_base/data_patch_hook/__manifest__.py new file mode 100644 index 0000000..e017a52 --- /dev/null +++ b/odex30_base/data_patch_hook/__manifest__.py @@ -0,0 +1,15 @@ +{ + 'name': 'Data Patches with Hook', + 'version': '18.0.1.0', # تم التحديث ليتوافق مع أودو 18 + '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', +} diff --git a/odex30_base/data_patch_hook/hooks.py b/odex30_base/data_patch_hook/hooks.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/odex30_base/data_patch_hook/hooks.py @@ -0,0 +1 @@ +