跳至內容
選單
此問題已被標幟
1 回覆
2638 瀏覽次數

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.
頭像
捨棄
作者 最佳答案

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})],
}])
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
1月 23
4719
1
6月 22
3031
1
5月 22
3345
1
12月 21
2651
4
3月 25
51028