我想计算一个字段在表单中编辑的次数,计数应该传递给另一个名为“编辑次数”的字段。以相同的形式。
答案 0 :(得分:0)
此代码工作正常..
def write(self, cr, uid, ids, vals, context=None):
quotation_obj=self.browse(cr, uid, ids,context=context)
if partner_id:
count = quotation_obj.number_of_edits + 1
vals.update({'number_of_edits': count})
return super(sale_order, self).write(cr, uid, ids, vals, context=context)
这是整个代码
def write(self, cr, uid, ids, vals, context=None):
partner_id=vals.get('partner_id')
quotation_obj=self.browse(cr, uid, ids,context=context)
if not partner_id:
#if partner id not found, find the employee ids
emp_ids=vals.get('employee_ids')
if emp_ids:
# for line in emp_ids:
# employee_ids=line[2]
# else:#update the employee ids
# employee_ids=quotation_obj.employee_ids
for line in emp_ids:
self.pool.get('res.partner').write(cr, uid, quotation_obj.partner_id.id, {'employee_ids': [(4, line[2])]}, context=context)
if partner_id:
emp_ids=vals.get('employee_ids')
if emp_ids:
for line in emp_ids:
self.pool.get('res.partner').write(cr, uid, partner_id, {'employee_ids': [(4, line[2])]}, context=context)
if partner_id:
count = quotation_obj.number_of_edits + 1
vals.update({'number_of_edits': count})
return super(sale_order, self).write(cr, uid, ids, vals, context=context)