Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions edi_core_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
EDI
===

..
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
Expand Down Expand Up @@ -64,6 +64,30 @@ In order to define a new Exchange Record, we need to configure:
- Backend
- Components

Exchange Records Retention
---------------------------

Configure automatic archiving and deletion of old exchange records per backend
to manage data retention and optimize performance.

Go to an EDI Backend form and open the **Auto Cleanup** tab. Two fields are
available:

- **Auto-archive records after (days)**: Archives exchange records older than
the specified number of days. Set to 0 to disable.

- **Auto-delete archived records after (days)**: Permanently deletes archived
exchange records older than the specified number of days. Set to 0 to disable.

Each backend can have different retention policies. Scheduled actions run
periodically to apply these settings:

- Archive job runs daily
- Delete job runs every 3 hours

To view archived records, use the "Archived" filter in the exchange records
search view.

Jobs
----

Expand Down Expand Up @@ -233,7 +257,7 @@ promote its widespread use.

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-simahawk| |maintainer-etobella|
|maintainer-simahawk| |maintainer-etobella|

This module is part of the `OCA/edi-framework <https://github.com/OCA/edi-framework/tree/18.0/edi_core_oca>`_ project on GitHub.

Expand Down
2 changes: 2 additions & 0 deletions edi_core_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"data/ir_actions_server.xml",
"data/sequence.xml",
"data/edi_configuration.xml",
"data/ir_cron_archive_old_edi_records.xml",
"data/ir_cron_delete_old_archived_edi_records.xml",
"security/res_groups.xml",
"security/ir_model_access.xml",
"views/edi_backend_views.xml",
Expand Down
27 changes: 27 additions & 0 deletions edi_core_oca/data/ir_cron_archive_old_edi_records.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="ir_cron_archive_old_edi_records" model="ir.cron">
<field name="name">Archive Old EDI Exchange Records</field>
<field name="model_id" ref="edi_core_oca.model_edi_exchange_record" />
<field name="state">code</field>
<field name="code">
# Archive old EDI exchange records based on backend configuration
backends = env['edi.backend'].search([
('auto_archive_records_after_days', '&gt;', 0)
])
for backend in backends:
cutoff_date = datetime.datetime.now() - datetime.timedelta(days=backend.auto_archive_records_after_days)
records = model.search([
('backend_id', '=', backend.id),
('create_date', '&lt;', cutoff_date),
('active', '=', True)
], limit=10000, order="create_date asc")
if records:
records.action_archive()
</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="active" eval="True" />
<field name="priority" eval="10" />
</record>
</odoo>
27 changes: 27 additions & 0 deletions edi_core_oca/data/ir_cron_delete_old_archived_edi_records.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="ir_cron_delete_old_archived_edi_records" model="ir.cron">
<field name="name">Delete Old Archived EDI Exchange Records</field>
<field name="model_id" ref="edi_core_oca.model_edi_exchange_record" />
<field name="state">code</field>
<field name="code">
# Delete old archived EDI exchange records based on backend configuration
backends = env['edi.backend'].search([
('auto_delete_records_after_days', '&gt;', 0)
])
for backend in backends:
cutoff_date = datetime.datetime.now() - datetime.timedelta(days=backend.auto_delete_records_after_days)
records = model.search([
('backend_id', '=', backend.id),
('create_date', '&lt;', cutoff_date),
('active', '=', False)
], limit=100, order="create_date asc")
if records:
records.unlink()
</field>
<field name="interval_number">3</field>
<field name="interval_type">hours</field>
<field name="active" eval="True" />
<field name="priority" eval="10" />
</record>
</odoo>
12 changes: 12 additions & 0 deletions edi_core_oca/models/edi_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ class EDIBackend(models.Model):
)
active = fields.Boolean(default=True)
company_id = fields.Many2one("res.company", string="Company")
auto_archive_records_after_days = fields.Integer(
string="Auto-archive records after (days)",
default=0,
help="Automatically archive EDI exchange records after X days. "
"Set to 0 to disable auto-archiving.",
)
auto_delete_records_after_days = fields.Integer(
string="Auto-delete archived records after (days)",
default=0,
help="Automatically delete archived EDI exchange records after X days. "
"Set to 0 to disable auto-deletion.",
)

@property
def exchange_record_model(self):
Expand Down
1 change: 1 addition & 0 deletions edi_core_oca/models/edi_exchange_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class EDIExchangeRecord(models.Model):
help="The record state can be rolled back manually in case of failure.",
)
company_id = fields.Many2one("res.company", string="Company")
active = fields.Boolean(default=True)

_sql_constraints = [
("identifier_uniq", "unique(identifier)", "The identifier must be unique."),
Expand Down
9 changes: 8 additions & 1 deletion edi_core_oca/views/edi_backend_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@
<field name="company_id" groups="base.group_multi_company" />
</group>
<!-- Hook to add more config -->
<notebook />
<notebook>
<page name="auto_cleanup" string="Records retention">
<group>
<field name="auto_archive_records_after_days" />
<field name="auto_delete_records_after_days" />
</group>
</page>
</notebook>
</sheet>
</form>
</field>
Expand Down
6 changes: 6 additions & 0 deletions edi_core_oca/views/edi_exchange_record_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@
help="Show all records created in the last 7 days"
/>
<separator />
<filter
string="Archived"
name="filter_archived"
domain="[('active', '=', False)]"
/>
<separator />
<field name="backend_id" />
<field name="type_id" />
<field name="res_id" />
Expand Down