【问题标题】:How to count the 'number of time a field is edited or updated' in Odoo 8?如何计算 Odoo 8 中“编辑或更新字段的次数”?
【发布时间】:2016-06-01 10:55:32
【问题描述】:

我想计算一个字段在一个表单中被编辑了多少次,这个计数应该传递给同一个表单中另一个名为“编辑次数”的字段。

【问题讨论】:

    标签: python count field openerp odoo-8


    【解决方案1】:

    这段代码运行良好..

    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)
    

    【讨论】:

    • 如果您对多个 ID/记录进行写入,这还不够。 partner_id 来自哪里?
    • 除了partner_id 为什么还不够。它会更新特定记录并更新计数,不是吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多