Skip to Content
Menu
This question has been flagged
1 Reply
1959 Views

I'd like to extend the function when registering a payment for a vendor invoice. Normally, the Vendor Reference (account_invoice.reference) is given to account_payment.communication. I want to write a module where I inherit from account_payment the moment the Vendor Reference is acquired from the invoice and add the invoice number to it.

Whichevery way I try to inherit from account.payment and the classes and functions from Odoo, I get a traceback the moment I click on "Validate" in the pop up after clicking on "Register Payment".

My code so far (since I think this is not that much):

# -*- coding: utf-8 -*-

from openerp import api, fields, models

class enhance_memo(models.Model):
    _inherit = 'account.payment'

    @api.model
    def default_get(self, values):
        record = super(enhance_memo,self).default_get(values)
        record['communication'] = [invoice['reference'], invoice['number']]
        return record

I already created another module, which extens the refund function, so I'm more than confused that I struggle with this one.

Any help, from links to tutorials to code examples would be really nice.


Avatar
Discard
Author Best Answer

Solved it. I forgot to get the invoice info:

# -*- coding: utf-8 -*-

from openerp import api, fields, models

class enhance_memo(models.Model):
_inherit = 'account.payment'

@api.model
def default_get(self, fields):
rec = super(enhance_memo, self).default_get(fields)
invoice_defaults = self.resolve_2many_commands('invoice_ids', rec.get('invoice_ids'))
if invoice_defaults and len(invoice_defaults) == 1:
invoice = invoice_defaults[0]
rec['communication'] = ['%s, %s' % (invoice['reference'], invoice['number']) ] or invoice['name'] or invoice['number']
return rec
Avatar
Discard
Related Posts Replies Views Activity
1
Nov 21
4698
0
Jul 24
3645
0
Oct 19
2177
0
Jul 18
3028
3
Jan 18
5574