0
votes

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,

2

2 Answers

0
votes

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

0
votes

You can use mapped() to gather a certain field from all records in a recordset.

How could I get all line_ids from all account_move_id of expense_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')