Skip to content
Snippets Groups Projects
Commit d958c866 authored by Emanuel Buzey's avatar Emanuel Buzey
Browse files

[FIX] Improved attachment management

parent f85e76cd
No related branches found
No related tags found
2 merge requests!195[REL] 14.0.2.0.0,!192[IMP] self_consumption: adding reports and documents
Pipeline #50100 passed
......@@ -174,6 +174,13 @@ class Selfconsumption(models.Model):
year = date.strftime("%Y")
file_name = f"{self.code}_{year}.txt"
existing_attachments = self.env["ir.attachment"].search(
[("res_model", "=", self._name), ("res_id", "=", self.id)]
)
if len(existing_attachments) > 0:
existing_attachments.unlink()
attachment = self.env["ir.attachment"].create(
{
"name": file_name,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment