This question has been flagged
3 Replies
2240 Views

I need to create a "reset" automated action for unset file which have been uploaded with a form in python code.

At the time this is what I have :

for rec in records:

rec['x_studio_proposition_bu_director'] = False
rec['x_studio_proposition_ceo'] = False
rec['x_studio_legal_proposition_approval'] = False

rec['x_studio_rnd_check'] = False
rec['x_studio_marketing_approval'] = False
rec['x_studio_rnd_comments'] = ""
rec['x_studio_marketing_comments'] = ""

remove(rec['x_studio_quote_file'])
rec['x_studio_proposal_file'] = ""
rec['x_studio_special_legal_attachment'] = ""

I'm trying some tests but I want to unset  x_studio_quote_file, x_studio_proposal_file and x_studio_special_legal_attachment. Other fields are unchecked or text emptied.

,How Can I do that ?
Avatar
Discard
Author

And before empty the fields, possible to copy the name of the file to another field(text by example) or better: create a new empty file field with new label (for keep historic) ?

Thanks Chris !

but  rec['x_studio_proposal_file'] = False doesn't work for delete an attachment

I tested it again in Odoo 12 and 13 and both images and file attachments disappear after the Automated Action is run. I will document it.

Best Answer

If you are asking how to delete an attachment, I think the following works:

rec['x_studio_proposal_file'] = False 

If you want to make a copy of the attachments, the simplest way might be to create a copy of the whole record and mark it as archived.  

for rec in records:     
rec['active'] = False old_name = rec.name rec['name'] = rec.name + " (archived)" rec.copy() rec['active'] = True rec['name'] = old_name rec['x_studio_proposal_file'] = False

Screenshots and notes

Avatar
Discard