Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
7084 Widoki

hi all

in this function i add new lines in "custody.settlement" custom model
the last line update function remove all old lines in my custom model and remain only newly one .. how to add new line in line_ids without remove old lines

Thanks

def button_post(self):
super(InheritAccountBankStatement, self).button_post()
for rec in self:
for line in rec.line_ids:
if line.account_type == 'custody' and line.selected == True:
custody = line.custody_settlement_id
move_vals = {
'name': line.payment_ref,
'date': line.date,
'partner_id': line.partner_id.id,
'ref': line.custody_settlement_id.name,
'journal_id': rec.journal_id.id,
}
move_id = custody.env['account.move'].create(move_vals)
custody.update({'line_ids': move_id})
Awatar
Odrzuć
Najlepsza odpowiedź

Hi,
 In order to fill a X2many field, we follow this syntax explained here : Filling X2M fields 
So in your case:

custody.update({'line_ids': [(4, move_id.id)]})

What i would suggest to increase performance is to use the bulk create : Instead of creating a record in each loop, you add a list of values ( list of dict that you append in each iteration ) and then you call create outside the loop with the list of values given in parameter.

This is possible since V13 via the api model_create_multi

Hope this helps.

Awatar
Odrzuć
Autor

Thanks ibrahim it works fine

Powiązane posty Odpowiedzi Widoki Czynność
5
paź 24
32498
1
lip 23
7172
2
lip 22
11401
2
paź 21
3211
0
sie 21
1960