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
2615 Widoki

I'm trying to create a new invoice in controller:


request.env['account.move'].sudo().create([
{
'move_type': 'out_invoice',
'journal_id': 1,
'invoice_date': '2020-01-10',
'invoice_line_ids': [(0, 0, {'product_id': 21, 'price_unit': 1000.0})],
}])

But i got this error 
Expected singleton: res.users()

Please help, thanks.
Awatar
Odrzuć
Autor Najlepsza odpowiedź

I've found the answer with the help of my leader, here it is:

This issue is because we missing "self.env.user", to do this, we must add .with_user(SUPERUSER_ID) after model call.

Example:



from odoo import SUPERUSER_ID

request.env['account.move'].with_user(SUPERUSER_ID).sudo().create([
{
'move_type': 'out_invoice',
'journal_id': 1,
'invoice_date': '2020-01-10',
'invoice_line_ids': [(0, 0, {'product_id': 21, 'price_unit': 1000.0})],
}])
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
sty 23
4715
1
cze 22
3019
1
maj 22
3342
1
gru 21
2641
4
mar 25
50972