如何按以前的记录值自动填充字段?

How to auto fill a field by previous record value?

在我的自定义模块中,有一个名为 closing_balance 的字段 float.closing 余额由 total_credit 计算 - total_debit.I 想要自动当特定员工创建下一条记录时,用 closing_balance 的值填充 float 类型的字段 opening_balance。

您需要覆盖该对象的 default_get 方法。

def default_get(self, cr, uid, fields, context=None):
    if context is None:
        context = {}
    res = super(hr_expense_expense, self).default_get(cr, uid, fields, context=context)

    #here is your logic
    opening_balance = 111 #do calculation as per your requirements

    #update opening balance field 
    res.update({'openning_balance_field_name': opening_balance})

    return res