1

I wanna add specific tag on tag_ids on ir.attachment with an Automated Action:

Code:

if record:
  if record.res_name and record.res_model_name == 'Task':
    key,name = record.res_name.split(" - ")
    rec =  env['project.task'].search([('key','=',key)])
    name_of_task = rec.key +" - " +rec.name
    if rec.x_studio_parent_project.x_assign_folder:  
      if rec.x_studio_level == "IMPLEMENTER":
        record._cr.execute("UPDATE ir_attachment SET folder_id = %s WHERE res_name= %s and res_model_name = 'Task'""",(rec.x_studio_parent_project.x_assign_folder.id, name_of_task))
      elif rec.x_studio_level == "SUPERVISOR":
        record._cr.execute("UPDATE ir_attachment SET folder_id = %s WHERE res_name= %s and res_model_name = 'Task'""",(rec.x_studio_parent_project.x_assign_folder.id, name_of_task))
    if rec.project_id.x_assign_folder:  
      if rec.x_studio_level == "INTERNAL CUSTOMER":
        record._cr.execute("UPDATE ir_attachment SET folder_id = %s WHERE res_name= %s and res_model_name = 'Task'""",(rec.project_id.x_assign_folder.id, name_of_task))

The code above is working but i wanna also change the tag id with specific document.facet id.

enter image description here

Tags = tag_ids: Many2many field

I tried:

record.write({'tag_ids':[66]})

record.write({'tag_ids':[(66)]})

record.tag_ids = [(66)]

record.tag_ids = [66]

record.tag_ids = 66

But none of them working any solution? Thanks in advance

Community
  • 1
  • 1
Fotic
  • 301
  • 5
  • 15
  • 1
    Does this answer your question? [insert into many2many odoo (former openerp)](https://stackoverflow.com/questions/9377402/insert-into-many2many-odoo-former-openerp) – CZoellner Mar 17 '20 at 07:51

2 Answers2

2

For a many2many field, a list of tuples is expected. Following are the list of how to pass tuples.

(0, 0, { values }) link to a new record that needs to be created with the given values dictionary

(1, ID, { values }) update the linked record with id = ID (write values on it)

(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)

(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)

(4, ID) link to existing record with id = ID (adds a relationship)

(5) unlink all (like using (3,ID) for all linked records)

(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

Adam Strauss
  • 1,889
  • 2
  • 15
  • 45
1

On Many2many field, you can do like this,

record.write({'tag_ids':[(6, 0, [ID])]})

Thanks

Dipen Shah
  • 2,396
  • 2
  • 9
  • 21