Reputation: 5496
I have the following for loop where account_move_id is a Many2one field:
...
for line in payment.move_line_ids + expense_sheet.account_move_id.line_ids:
...
I have modified account_move_id making it a Many2many field. Hence when I run the code I get an "expected singleton" exception in the for loop line.
Given that now account_move_id is a Many2many field, how could I get all line_ids from all account_move_ids of expense_sheet?
Thanks,
Upvotes: 0
Views: 489
Reputation: 2135
You can use mapped()
to gather a certain field from all records in a recordset.
How could I get all
line_ids
from allaccount_move_id
ofexpense_sheet
?
# If account_move_id is a recordset, mapped will get line_ids for all of them
line_ids = expense_sheet.account_move_id.mapped('line_ids')
Upvotes: 0
Reputation: 14721
I don't where is the problem exactly but when you get this error most likely you where trying to acces a field but in recordSet that contains more than one record.
When you use decorator api.multi self in the method can contains more than one record so to avoid this error always loop through self.
for rec in self:
# here rec will alawys contain just one record
rec.some_field
so this error can happen in one2many field basically check where did you acces a field or method in a recordSet
Upvotes: 0