繁体   English   中英

为什么会出现错误:“ int”对象没有属性“ create”?

[英]Why am I getting the error: 'int' object has no attribute 'create'?

码:

 @api.multi
    def open_second_class(self):
        ac = self.env['ir.model.data'].xmlid_to_res_id('account.invoice_form', raise_if_not_found=True)
        write_obj = ac.create({'partner_id': self.name_id})
        accountant = False
        for o in self:
            accountant = o.id
        result = {
            'name': '2nd class',
            'view_type': 'form',
            'res_model': 'account.invoice',
            'res_id': write_obj.id,
            'view_id': False,
            'context': {'default_id_tbl1': accountant},
            'type': 'ir.actions.act_window',
            'view_mode': 'form',
            'target': 'new',
            'domain': '[]'
        }
        return result

错误:

Traceback (most recent call last):
          File "C:\Program Files\Odoo 9.0-20170919\server\.\openerp\http.py", line 650, in _handle_exception
          File "C:\Program Files\Odoo 9.0-20170919\server\.\openerp\http.py", line 687, in dispatch
          File "C:\Program Files\Odoo 9.0-20170919\server\.\openerp\http.py", line 323, in _call_function
          File "C:\Program Files\Odoo 9.0-20170919\server\.\openerp\service\model.py", line 118, in wrapper
          File "C:\Program Files\Odoo 9.0-20170919\server\.\openerp\http.py", line 316, in checked_call
          File "C:\Program Files\Odoo 9.0-20170919\server\.\openerp\http.py", line 966, in __call__
          File "C:\Program Files\Odoo 9.0-20170919\server\.\openerp\http.py", line 516, in response_wrap
          File "C:\Program Files\Odoo 9.0-20170919\server\openerp\addons\web\controllers\main.py", line 899, in call_button
          File "C:\Program Files\Odoo 9.0-20170919\server\openerp\addons\web\controllers\main.py", line 887, in _call_kw
          File "C:\Program Files\Odoo 9.0-20170919\server\.\openerp\api.py", line 250, in wrapper
          File "C:\Program Files\Odoo 9.0-20170919\server\.\openerp\api.py", line 381, in old_api
          File "C:\Users\Amandnoever\AppData\Local\OpenERP S.A.\Odoo\addons\9.0\accountant\models\models.py", line 48, in open_second_class
        AttributeError: 'int' object has no attribute 'create'

使用self.env.ref('external_id')代替xmlid_to_res_id方法。 但是我认为您想要做的是这样的:

@api.multi
def open_second_class(self):
    self.ensure_one()
    ac = self.env.ref('account.invoice_form')
    invoice = self.env['account.invoice'].create({
        'partner_id': self.name_id.id
    })

    return {
        'name': '2nd class',
        'type': 'ir.actions.act_window',
        'res_model': 'account.invoice',
        'res_id': invoice.id,
        'view_type': 'form',
        'view_mode': 'form',
        'target': 'new',
        'context': {'default_id_tbl1': self.env.id },
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM