Skip to content

Commit e551b22

Browse files
committed
feat(edi_core_oca): add backend-controlled auto-cleanup for exchange records
Add configurable auto-archiving and auto-deletion of EDI exchange records per backend. This backend-specific settings that can be managed individually.
1 parent 90cc5e6 commit e551b22

5 files changed

Lines changed: 52 additions & 17 deletions

File tree

edi_core_oca/data/ir_cron_archive_old_edi_records.xml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
<field name="model_id" ref="edi_core_oca.model_edi_exchange_record" />
66
<field name="state">code</field>
77
<field name="code">
8-
9-
cutoff_date = datetime.datetime.now() - datetime.timedelta(days=15)
10-
records = model.search([
11-
('create_date', '&lt;', cutoff_date),
12-
('active', '=', True)
13-
], limit=10000, order="create_date asc")
14-
if records:
15-
records.action_archive()
8+
# Archive old EDI exchange records based on backend configuration
9+
backends = env['edi.backend'].search([
10+
('auto_archive_records_after_days', '&gt;', 0)
11+
])
12+
for backend in backends:
13+
cutoff_date = datetime.datetime.now() - datetime.timedelta(days=backend.auto_archive_records_after_days)
14+
records = model.search([
15+
('backend_id', '=', backend.id),
16+
('create_date', '&lt;', cutoff_date),
17+
('active', '=', True)
18+
], limit=10000, order="create_date asc")
19+
if records:
20+
records.action_archive()
1621
</field>
1722
<field name="interval_number">1</field>
1823
<field name="interval_type">days</field>

edi_core_oca/data/ir_cron_delete_old_archived_edi_records.xml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
<field name="model_id" ref="edi_core_oca.model_edi_exchange_record" />
66
<field name="state">code</field>
77
<field name="code">
8-
9-
cutoff_date = datetime.datetime.now() - datetime.timedelta(days=30)
10-
records = model.search([
11-
('create_date', '&lt;', cutoff_date),
12-
('active', '=', False)
13-
], limit=100, order="create_date asc")
14-
if records:
15-
records.unlink()
8+
# Delete old archived EDI exchange records based on backend configuration
9+
backends = env['edi.backend'].search([
10+
('auto_delete_records_after_days', '&gt;', 0)
11+
])
12+
for backend in backends:
13+
cutoff_date = datetime.datetime.now() - datetime.timedelta(days=backend.auto_delete_records_after_days)
14+
records = model.search([
15+
('backend_id', '=', backend.id),
16+
('create_date', '&lt;', cutoff_date),
17+
('active', '=', False)
18+
], limit=100, order="create_date asc")
19+
if records:
20+
records.unlink()
1621
</field>
1722
<field name="interval_number">3</field>
1823
<field name="interval_type">hours</field>

edi_core_oca/models/edi_backend.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ class EDIBackend(models.Model):
6262
)
6363
active = fields.Boolean(default=True)
6464
company_id = fields.Many2one("res.company", string="Company")
65+
auto_archive_records_after_days = fields.Integer(
66+
string="Auto-archive records after (days)",
67+
default=0,
68+
help="Automatically archive EDI exchange records after X days. "
69+
"Set to 0 to disable auto-archiving.",
70+
)
71+
auto_delete_records_after_days = fields.Integer(
72+
string="Auto-delete archived records after (days)",
73+
default=0,
74+
help="Automatically delete archived EDI exchange records after X days. "
75+
"Set to 0 to disable auto-deletion.",
76+
)
6577

6678
@property
6779
def exchange_record_model(self):

edi_core_oca/views/edi_backend_views.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@
5757
<field name="company_id" groups="base.group_multi_company" />
5858
</group>
5959
<!-- Hook to add more config -->
60-
<notebook />
60+
<notebook>
61+
<page name="auto_cleanup" string="Auto Cleanup">
62+
<group>
63+
<field name="auto_archive_records_after_days" />
64+
<field name="auto_delete_records_after_days" />
65+
</group>
66+
</page>
67+
</notebook>
6168
</sheet>
6269
</form>
6370
</field>

edi_core_oca/views/edi_exchange_record_views.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@
265265
help="Show all records created in the last 7 days"
266266
/>
267267
<separator />
268+
<filter
269+
string="Archived"
270+
name="filter_archived"
271+
domain="[('active', '=', False)]"
272+
/>
273+
<separator />
268274
<field name="backend_id" />
269275
<field name="type_id" />
270276
<field name="res_id" />

0 commit comments

Comments
 (0)