Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
7 Trả lời
5556 Lượt xem

Hi all

i have code like this

class mtc_hr_analytic_timesheet(osv.osv):

    _inherit = 'hr.analytic.timesheet'

    _columns = {

                    'approver' : fields.many2one('res.users','Approver',readonly=True),

    }


i want value in field approver store to my database. but when i use readonly its doesnt work. the value dissapear when i save.

i have use strore=True but its doesnt work.

anyone can help me how to solve this problem??


Thanks before

Ảnh đại diện
Huỷ bỏ
Tác giả

Can you give an example code of the contents of xyz_id ?

for example, to get the id of the ERP Manager

users_ids = self.pool.get('res.users').search(cr, uid, [])

for _id in users_ids:

if self.pool['res.users'].has_group(cr, _id, 'base.group_erp_manager')

xyz_id = _id

Câu trả lời hay nhất

Hey Susi!, Hope this will work for u.. 

samp_cal1=fields.Integer(string="a")

samp_cal2=fields.Integer(string="b")

samp_cal3=fields.Integer(string="c",readonly=True)


@api.onchange('samp_cal1','samp_cal2')

def adding_samp(self):

    self.samp_cal3=self.samp_cal1+self.samp_cal2

@api.model

def create(self,vals):

    if self.samp_cal3:

        vals['samp_cal3']=self.samp_cal1+self.samp_cal2

    res = super(tokenreservation, self).create(vals)

    return res

@api.multi

def write(self,vals):

    if not self.samp_cal3:

        vals['samp_cal3'] = self.samp_cal1+self.samp_cal2

    res = super(tokenreservation, self).write(vals)

    return res

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

assighn values like this



cr.execute("UPDATE  hr_analytic_timesheet SET approver = %s where id = %s ", (  your value, id of object ))

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

try to write the value into the field using SQL query

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You can update a many2one field, with either an ID or record.

You can’t put any ID or record, a check is made on the relationship to ensure data integrity

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

 You have to set the value of this field in the create method explicitly

def create(self, cr, uid, val, context=None):
...
val['approve'] = xyz_id # this is the user id you decided that he will do the approval
res = super(you_class, self).create(cr, uid, val, context)
return res





Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 25
1269
0
thg 1 25
3337
1
thg 10 24
1534
1
thg 8 23
14630
change password Đã xử lý
1
thg 8 23
13276