Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2979 Lượt xem

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.


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 21
6049
0
thg 7 24
4536
0
thg 10 19
3173
0
thg 7 18
3885
3
thg 1 18
6168