在v8中覆盖字段功能的方法

时间:2016-12-01 21:06:06

标签: python openerp odoo-8

我想在Odoo中覆盖原始字段函数。

根据答案:Odoo: How to override original function 我只需要定义与原始模型完全相同的方法。所以这是我的代码:

class paiement_client_difference_montant(models.Model):
    _inherit="account.voucher"

    #writeoff_amount=fields.Float(compute='_get_writeoff_amount')

def _get_writeoff_amount(self, cr, uid, ids, name, args, context=None):
    print '_get_writeoff_amount _inherit'
    if not ids: return {}
    currency_obj = self.pool.get('res.currency')
    res = {}
    for voucher in self.browse(cr, uid, ids, context=context):
        debit = credit = 0.0
        sign = voucher.type == 'payment' and -1 or 1
        for l in voucher.line_dr_ids:
            debit += l.amount
        for l in voucher.line_cr_ids:
            credit += l.amount
        currency = voucher.currency_id or voucher.company_id.currency_id
        res[voucher.id] =  currency_obj.round(cr, uid, currency, voucher.amount - sign * (credit - debit))
    return res

但是从未达到过该代码。 请帮忙。谢谢。

1 个答案:

答案 0 :(得分:2)

您必须在类中再次覆盖该字段,才能执行此新创建的方法。