Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
2135 Näkymät

I have the following code:


def action_adjust_amount_currency(self):
for rec in self:
if rec.manual_currency_rate_active==True:
rec.line_ids.debit=rec.line_ids.debit*rec.manual_currency_rate
rec.line_ids.credit=rec.line_ids.credit*rec.manual_currency_rate

else:
return False

I am having this error: 


ValueError: Expected singleton: account.move.line(111717, 111718, 111719)


How can I fix it?


Avatar
Hylkää
Paras vastaus

Hi,

The error you are seeing occurs when you try to access an attribute of a collection of objects (in this case rec.line_ids) as if it were a single object.

To fix this error, you need to iterate over the line_ids collection and set the debit and credit attributes for each object in the collection.

Here's an example of how you could modify your code to do this:

def action_adjust_amount_currency(self):
for rec in self:
if rec.manual_currency_rate_active==True:
for line in rec.line_ids:
line.debit = line.debit * rec.manual_currency_rate
line.credit = line.credit * rec.manual_currency_rate
else:
return False

Regards

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
4
helmik. 24
4692
1
marrask. 22
2187
2
kesäk. 25
2106
1
maalisk. 25
1780
0
jouluk. 24
1056