Mack
Mack

Reputation: 13

How can override default_get in odoo9?

I want to override default_get in odoo9 and My code

class account_payment(models.Model):
_inherit = "account.payment"

    @api.model
    def default_get(self, fields):
        #print 'PRINT1',MAP_INVOICE_TYPE_PARTNER_TYPE
        rec = super(account_payment, 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'] = invoice['reference'] or invoice['name'] or invoice['number']
            rec['currency_id'] = invoice['currency_id'][0]
            rec['payment_type'] = invoice['type'] in ('out_invoice', 'in_refund', 'sponsor_invoice',) and 'inbound' or 'outbound'  # modified for charity
            rec['partner_type'] = MAP_INVOICE_TYPE_PARTNER_TYPE[invoice['type']]
            rec['partner_id'] = invoice['partner_id'][0]
            rec['amount'] = invoice['residual']
        return rec

but when I click create it shows an error message, that point the inherited class first then calling base class, how is that possible? Please help.

Error message:

File "/opt/odoo_v9_charity/server/addons/web_charity/models/account_payment.py", line 87, in default_get rec = super(account_payment_charity, self).default_get(fields) File "/opt/odoo_v9_charity/server/openerp/api.py", line 248, in wrapper return new_api(self, *args, **kwargs) File "/opt/odoo_v9_charity/server/openerp/addons/account/models/account_payment.py", line 257, in default_get rec['partner_type'] = MAP_INVOICE_TYPE_PARTNER_TYPE[invoice['type']] KeyError: u'sponsor_out_invoice'

Upvotes: 0

Views: 168

Answers (1)

CZoellner
CZoellner

Reputation: 14776

The dict/map MAP_INVOICE_TYPE_PARTNER_TYPE simply does not have the key 'sponsor_out_invoice'. Maybe you should add it.

Upvotes: 0

Related Questions