Skip to content

Commit b372147

Browse files
committed
[IMP] database_cleanup: changes from review
1 parent 851d4ef commit b372147

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

database_cleanup/models/purge_attachments.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
from odoo import _, api, fields, models
77
from odoo.exceptions import AccessError, UserError, ValidationError
88

9+
REASON_MISSING_FILE = "missing_file"
10+
911

1012
class CleanupPurgeLineAttachment(models.TransientModel):
1113
_inherit = "cleanup.purge.line"
1214
_name = "cleanup.purge.line.attachment"
1315
_description = "Cleanup Purge Line Attachment"
1416

1517
attachment_id = fields.Many2one("ir.attachment")
18+
reason = fields.Selection(
19+
[
20+
(REASON_MISSING_FILE, ("File missing in filestore")),
21+
],
22+
)
1623
wizard_id = fields.Many2one("cleanup.purge.wizard.attachment", readonly=True)
1724

1825
def purge(self):
@@ -92,6 +99,7 @@ def find(self):
9299
{
93100
"attachment_id": attach.id,
94101
"name": attach.store_fname or attach.name or str(attach.id),
102+
"reason": REASON_MISSING_FILE,
95103
},
96104
)
97105
)

database_cleanup/tests/test_purge_attachments.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from unittest.mock import patch
77

88
from odoo.exceptions import UserError
9+
from odoo.fields import Command
910
from odoo.tests.common import tagged
1011

1112
from .common import Common, environment
@@ -117,22 +118,18 @@ def patched_unlink(self):
117118
wizard = env["cleanup.purge.wizard.attachment"].create(
118119
{
119120
"purge_line_ids": [
120-
(
121-
0,
122-
0,
121+
Command.create(
123122
{
124123
"attachment_id": protected_id,
125124
"name": orphan_protected.store_fname
126125
or str(protected_id),
127-
},
126+
}
128127
),
129-
(
130-
0,
131-
0,
128+
Command.create(
132129
{
133130
"attachment_id": other_id,
134131
"name": orphan_other.store_fname or str(other_id),
135-
},
132+
}
136133
),
137134
],
138135
}

database_cleanup/views/purge_attachments.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<field name="arch" type="xml">
88
<field name="name" position="after">
99
<field name="attachment_id" />
10+
<field name="reason" />
1011
</field>
1112
</field>
1213
</record>
@@ -31,6 +32,7 @@
3132
<field name="arch" type="xml">
3233
<field name="name" position="after">
3334
<field name="attachment_id" />
35+
<field name="reason" />
3436
</field>
3537
</field>
3638
</record>

0 commit comments

Comments
 (0)