Skip to content

Commit

Permalink
[FIX] Access error on ir.attachment create
Browse files Browse the repository at this point in the history
As normal user only have read access to delay.export, we need sudo to chreate an attachment on this record

Use user 6 (Marc Demo) in the tests, not admin (2)
  • Loading branch information
hhgabelgaard committed Oct 31, 2023
1 parent 55ad859 commit 47b087d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 12 additions & 8 deletions base_export_async/models/delay_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,18 @@ def export(self, params):
export_record = self.sudo().create({"user_ids": [(6, 0, users.ids)]})

name = "{}.{}".format(model_name, export_format)
attachment = self.env["ir.attachment"].create(
{
"name": name,
"datas": base64.b64encode(content),
"type": "binary",
"res_model": self._name,
"res_id": export_record.id,
}
attachment = (
self.env["ir.attachment"]
.sudo()
.create(
{
"name": name,
"datas": base64.b64encode(content),
"type": "binary",
"res_model": self._name,
"res_id": export_record.id,
}
)
)

url = "{}/web/content/ir.attachment/{}/datas/{}?download=true".format(
Expand Down
4 changes: 2 additions & 2 deletions base_export_async/tests/test_base_export_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"domain": [],
"context": {"lang": "en_US", "tz": "Europe/Brussels", "uid": 2},
"import_compat": false,
"user_ids": [2]
"user_ids": [6]
}"""
}

Expand All @@ -35,7 +35,7 @@
"domain": [],
"context": {"lang": "en_US", "tz": "Europe/Brussels", "uid": 2},
"import_compat": false,
"user_ids": [2]
"user_ids": [6]
}"""
}

Expand Down

0 comments on commit 47b087d

Please sign in to comment.