콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

Hi,

I'm trying to create entries from template, for example when user choose template from the list the list below (One2Many) should be crated from the template lines, but I have bad query error plus when the method update the list I can see its not correct, the product and equipment is missing, here's my code:

class cmms_accessory(models.Model):
_name = 'cmms.accessory'
_description = 'Equipment Accessory'

name = fields.Char(related='product.name')
equipment_id = fields.Many2one('cmms.equipment', 'Serial Number', required=True)
product = fields.Many2one('product.product', 'Product', required=True)
photo = fields.Binary(string="Image", related="product.image")
revision_number = fields.Char(string='Revision Number', help='E.g 2.0')
revision_description = fields.Char(string='Revision Description', help='E.g Chogori/ Black Remote')
state = fields.Selection([('ok', 'OK'), ('in_transit', 'In Transit'), ('replaced', 'Replaced'), ('fault', 'Fault'),
('returned', 'Returned')], string='Status', default='ok')
serial = fields.Char(string='Serial Number')
additional_info = fields.Char(string='Additional Information')
Here's the error :
odoo.sql_db: bad query: INSERT INTO "cmms_accessory" ("id", "product", "revision_description", "equipment_id", "state", "revision_number", "serial", "create_uid", "write_uid", "create_date", "write_date") VALUES(nextval('cmms_accessory_id_seq'), NULL, NULL, 1, '
ok', '1', NULL, 1, 1, (now() at time zone 'UTC'), (now() at time zone 'UTC')) RETURNING id
and here's my onchange method in different class
@api.onchange('template_id')
def _add_accessories(self):
if not self.template_id:
return

template = self.template_id.accessory_template
accessories_lines = []

for line in template:
aa = line.accessory_template
data = {
'product.id': aa.product.id, # M2O
'revision_description': aa.revision_description, # Char
'equipment_id': self.id, #M2O
'state': 'ok', # Selection
'revision_number': aa.revision_number, # Char
'serial': None, # Char
'photo': aa.photo,#Binary
'additional_info': None,#Char
}

accessories_lines.append((0, 0, data))
self.accessory = accessories_lines;
아바타
취소
작성자

Fixed.. missed product(.id) and used self.updated. Closed!

관련 게시물 답글 화면 활동
1
3월 15
19003
0
2월 19
3454
1
6월 17
5026
0
3월 15
8008
0
9월 20
3035