跳至内容
菜单
此问题已终结
3 回复
3301 查看

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 ?
形象
丢弃
编写者

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.

最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
3
2月 24
1890
1
4月 23
8344
1
12月 24
1218
2
3月 24
1698
2
2月 23
4121