如何在odoo9中覆盖default_get?

时间:2016-11-16 05:36:19

标签: python-2.7 openerp odoo-9

我想覆盖odoo9和我的代码

中的default_get
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

但是当我点击创建它会显示一条错误消息时,首先指出继承的类然后调用基类,这怎么可能?请帮忙。

错误讯息:

  

文件“/opt/odoo_v9_charity/server/addons/web_charity/models/account_payment.py”,第87行,在default_get中         rec = super(account_payment_charity,self).default_get(fields)       在包装器中输入“/opt/odoo_v9_charity/server/openerp/api.py”,第248行         返回new_api(self,* args,** kwargs)       在default_get中输入文件“/opt/odoo_v9_charity/server/openerp/addons/account/models/account_payment.py”,第257行         rec ['partner_type'] = MAP_INVOICE_TYPE_PARTNER_TYPE [invoice ['type']]       KeyError:u'sponsor_out_invoice'

1 个答案:

答案 0 :(得分:0)

字典/地图$ git diff --name-status 3cdd5d1 3ab2281 M .travis.yml M Documentation/RelNotes/2.10.2.txt M Documentation/RelNotes/2.11.0.txt M Documentation/config.txt M Documentation/diff-config.txt ... 根本没有密钥MAP_INVOICE_TYPE_PARTNER_TYPE。也许你应该添加它。