I'm trying to update One2many field inside onchange method.
As documentation says I'm using update method, and not standard CRUD methods like create.
I have this piece of code:
class HrExpenseSheet(models.Model):
_inherit = "hr.expense.sheet"
@api.onchange('employee_id')
def _update_expense_ids(self):
# define variables ...
values = {
'product_id': product_id,
'name': name,
'product_uom_id': product_uom_id,
'unit_amount': unit_amount,
'quantity': quantity,
'total_amount': total_amount
}
self.update({'expense_line_ids':[(0, 0, values)]})
It almost works. I get my record added to the table but after that whole table just breaks... When this code executes couple things happen:
I'm not able to save the document because supposedly required unit_amount is not filled in - it clearly should be
When I'm trying to edit that particular line I'm not able to because it takes me to a completely new record without my data filled in (but data is present on the table view)
I'm not able to add new row because when I click the button I get error psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type integer: "virtual_2509" LINE 1: ...mpany_id" = 1)) AND (("hr_expense"."id" not in ('virtual_2...
What the hell is happening. I've had the same code running on version 8.0 without problem but this does not work on 13.0.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
1
Trả lời
4554
Lượt xem
Hi,
Try update your code like below.
@api.onchange('employee_id')
def _update_expense_ids(self):
# define variables ...
values = [{
'product_id': product_id,
'name': name,
'product_uom_id': product_uom_id,
'unit_amount': unit_amount,
'quantity': quantity,
'total_amount': total_amount
}]
self.update({'expense_line_ids': [(6, 0, values)]})
Hope it helps
Does not work. I get an error
File "/usr/lib/python3/dist-packages/odoo/api.py", line 745, in get
value = self._data[field][record._ids[0]]
TypeError: unhashable type: 'dict'
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
0
thg 7 22
|
3659 | ||
|
1
thg 1 21
|
3364 | ||
|
0
thg 12 21
|
3070 | ||
One2many field domain not working
Đã xử lý
|
|
2
thg 12 21
|
5990 | |
On change is not triggered
Đã xử lý
|
|
1
thg 1 21
|
5102 |