Skip to Content
Menu
This question has been flagged

Hey what i want to achieve here is that if have 5 line in a journal entry and i want to add same analytic tag in each field on a button click . If i add one in the first line i want it to populate in the rest on a button click.

Right now i have done it with copy function but it doesnt feel right

i am using   

self.copy(default={'analytic_tag_ids': self.analytic_tag_ids})

Can u suggest a better way of achieving it
Avatar
Discard
Best Answer

Try the following code:

tag_ids = []
for line in self.line_ids:
if line.analytic_tag_ids:
# Take tags from the line and then break the loop
tag_ids = line.analytic_tag_ids
break

if tag_ids:
for tag_id in tag_ids:
# Write each tag to every line
self.line_ids.write({'analytic_tag_ids': [(4, tag_id)]})


Avatar
Discard
Author

Hey Thanks for your answer can u plz tell what this "4" represents?

Author

Thanks i'll try and mark true after confirmation

Author

Yup this works. Thank you so much man! Just a correction in the last line

self.line_ids.write({'analytic_tag_ids': [(4, tag_id.id)]})

Author Best Answer

i was able to make a list and change its values based on the first tag in the line using this code

lines = [line.analytic_tag_ids.id for line in self.line_ids]
#print(lines)
line1 = lines[0]
# print(line1)

for index,line in enumerate(lines):
print('line1',line1)
print('index',index)
# print('line1', lines[line1])
new= lines[line] = lines[0]
But now how to pass it to odoo to create record based on that
Avatar
Discard
Related Posts Replies Views Activity
0
Aug 20
2655
1
Nov 24
150
0
Jan 24
384
0
Nov 23
344
1
Nov 23
458