commit
a636c63679
|
|
@ -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.")
|
||||||
|
|
||||||
|
|
@ -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',
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
Loading…
Reference in New Issue