如何覆盖 odoo9 中的 default_get?
How can override default_get in odoo9?
我想覆盖 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
但是当我点击创建时它显示了一条错误消息,指出继承 class 先调用基础 class,这怎么可能?请帮忙。
错误信息:
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'
dict/mapMAP_INVOICE_TYPE_PARTNER_TYPE
根本就没有钥匙'sponsor_out_invoice'
。也许你应该添加它。
我想覆盖 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
但是当我点击创建时它显示了一条错误消息,指出继承 class 先调用基础 class,这怎么可能?请帮忙。
错误信息:
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'
dict/mapMAP_INVOICE_TYPE_PARTNER_TYPE
根本就没有钥匙'sponsor_out_invoice'
。也许你应该添加它。