0
votes

I want to override a original field function in Odoo.

According to the answer here: Odoo: How to override original function i just have to define exactly the same method as in the original model. So here is my code:

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

But that code is never reached. Any help please. Thank you.

1
This is possibly an indentation problem, i edited your question and fixed it, your class never _inherited from account.voucher because the inherit field was outside the class blockdanidee
By field you mean't writeoff_amount . It's a comment.By the way i've tried with your change and it still doesn't work.Oumar Diarra
writeoff_amount is a field in base account.voucher?gabrieloliveira
@gabrieloliveira Yes.Oumar Diarra
@OumarDiarra i meant _inherit = account.voucher it was outside the class block....i edited your question and fixed it.danidee

1 Answers

2
votes

You have to override that field again in your class, to execute this newly created method.