Odoo警告-记录丢失:记录不存在或已被删除

时间:2018-10-29 11:39:42

标签: python odoo-10

我正在尝试将记录创建到document.propose.in模型中。但是,当我单击data_create按钮时收到警告。我试图检查代码哪里出了问题,这是这一行中的代码:

message_obj.create({
                'res_id': self.ids[0],
                'model': 'document.propose.in',
                'subtype_id': subtype_id,
                'body': _('Changes in the document %s has been approved by QMR.') % self.name
                })

终端上没有显示错误信息。但是,它确实显示在浏览器的控制台中。

  

web.assets_common.js:3023服务器应用程序错误{“ message”:“ Odoo Server Error”,“ code”:200,“ data”:{“ debug”:“ Traceback(最近一次呼叫):\ n _handle_exception \ n中的文件\“ / home / odoo10 / odoo / http.py \” \ n返回super(JsonRequest,self)。_handle_exception(异常)\ n File \“ / home / odoo10 / odoo / http.py \“,第677行,在dispatch \ n result = self._call_function(** self.params)\ n File \” / home / odoo10 / odoo / http.py \“,第333行,_call_function \ n返回checked_call( self.db,* args,** kwargs)\ n文件\“ / home / odoo10 / odoo / service / model.py \”,第101行,在包装器中\ n返回f(dbname,* args,** kwargs) \ n在checked_call文件\“ / home / odoo10 / odoo / http.py \”,行326 \ n结果= self.endpoint(* a,** kw)\ n文件\“ / home / odoo10 / odoo / http.py \“,第935行,在调用 \ n中返回self.method(* args,** kw)\ n文件\” / home / odoo10 / odoo / http.py \“,第506行,在response_wrap \ n响应= f(* args,** kw)\ n文件\“ / home / odoo10 / addons / web / controllers / main.py \”,第889行中call_button \ n action = self._call_kw(model,method,args,{})\ n File” /home/odoo10/addons/web/controllers/main.py \”,行877,在_call_kw \ n中返回call_kw( request.env [model],方法,args,kwargs)\ n文件\“ / home / odoo10 / odoo / api.py \”,行689,在call_kw \ n中返回call_kw_multi(方法,模型,args,kwargs)\ n call_kw_multi中的文件\“ / home / odoo10 / odoo / api.py \”,行680 \ n结果=方法(recs,* args,** kwargs)\ n文件\“ / home / innotek4 / Documents / ISO /odoo_komp/mgmt_documents/wizards/document_register.py \“,在data_create \ n'body'中的第113行:_('文档%s的更改已由QMR批准。')%self.name \ n文件\” /home/odoo10/addons/mail/models/mail_message.py \“,第724行,位于create \ n values ['record_name'] = self._get_record_name(值)\ n文件\” / home / odoo10 / addons / mail /models/mail_message.py \“,行_get_record_name \ n中的第680行,返回self.env [model] .sudo()。browse(res_id).name_get()[0] [1] \ n文件\” / home / odoo10 / odoo / models.py \“,第1546行,在name_get \ n中result.append((record.id,convert(record [name],record)))\ n文件\“ / home / odoo10 / odoo / models.py \”,行5211,在 getitem 中\ n返回self._fields [key]。获取((self,type(self)))\ n 第913行的文件“ /home/odoo10/odoo/fields.py \” >获取 \ n值= record._cache [self] \ n文件\“ / home / odoo10 / odoo / models.py \”,第5563行,在 getitem \ n中返回值.get()如果isinstance(value,SpecialValue)否则为value \ n File \“ / home / odoo10 / odoo / fields.py \”,第48行,在get \ n中引发self.exception \ nMissingError:(u'Record确实不存在或已被删除。',None)\ n“,” exception_type“:” missing_error“,” message“:”记录不存在或已被删除。\ nNone“,” name“:” odoo.exceptions。 MissingError“,”参数“:[”记录不存在或已被删除。“,null]}}

第113行是函数创建message_obj的位置。我试过更新模块,但是没有运气。这是代码(以防万一):

class documentregister(models.TransientModel):
_name = "document.register"
_description = "document register"

name = fields.Char('Title', required=True)
type = fields.Selection(
    [('content', 'Content'), ('category', 'Category')],
    'Type',
    help="Page type",
    default="content"
)
act = fields.Selection(
    [('create', 'Create'), ('edit', 'Edit')],
    'Action'
)
parent_id = fields.Many2one(
    'document.page',
    'Category',
    domain=[('type', '=', 'category')]
)
doc_page = fields.Many2one('document.page','Document')
content = fields.Text("Content")
revision = fields.Integer('Revision', default=0)
doc_no = fields.Char('Document Number')
dept = fields.Many2one('hr.department', 'Department',domain=[('parent_id', '=', False)])
section = fields.Many2one('hr.department','Section')
id_dpi = fields.Many2one('document.propose.in', 'id_dpi')
document_attc1 = fields.Many2many(comodel_name='ir.attachment', relation='document_propose_attachment_wiz', string="Add Attachment")
issue_plan = fields.Date('Document Issue Plan')
distribution_ids = fields.One2many('document.distribusi.regis', 'doc_id', 'Distribution Dept')

@api.multi
def data_create(self):
    if self.act =="create":
        if self.content:
            document_page_obj = self.env['document.page']
            masterdist=[]
            for di in self.id_dpi.distribusi_ids:
                masterdist2=(0, 0, {'dept':di.dept.id})
                masterdist.append(masterdis2)
            id_create = document_page_obj.create(
                {'name': self.name,
                 'type': 'content',
                 'dept': self.dept.id,
                 'section': self.section.id,
                 'doc_no': self.doc_no,
                 'content': self.content,
                 'parent_id': self.parent_id.id,
                 'write_uid': self.env.uid,
                 'write_date': time.strftime('%Y-%m-%d'),
                 'distribusi_ids': masterdist,
                 }
            )
            document_page_history_obj = self.env['document.page.history']
            dph_ids_list = document_page_history_obj.search([('page_id', '=', id_create.id)])
            dph_ids_list.sorted(key=lambda r: r.id)
            attach = []
            for att in self.document_attc1:
                attach.append(att.id)
            dph_ids_list.write({'date_confirm': self.issue_plan,'lamp':[(6, 0,attach)]})
            id_create.page_approval_approved2()
            id_create.distribusi_act()
            document_page_in_obj = self.env['document.propose.in']
            model_data_obj = self.env['ir.model.data']
            message_obj = self.env['mail.message']
            subtype_id = model_data_obj.get_object_reference('mail', 'mt_comment')[1]
            message_obj.create({
                'res_id': self.ids[0],
                'model': 'document.propose.in',
                'subtype_id': subtype_id,
                'body': _('Changes in the document %s has been approved by QMR.') % self.name
                })
            return self.id_dpi.write({'date_limit': time.strftime('%Y-%m-%d'),'confirm_id': self.env.uid,'propose_id_new': id_create.id,'state': 'convert','doc_regis_bool':True})
        else:
            raise osv.except_osv(_('Invalid Action!'), _('Please Entry Content Document First!'))

    elif self.act=="edit":
        if self.content:
            document_page_obj = self.env['document.page']
            dp_ids=document_page_obj.search([('id', '=',self.doc_page.id)])[0]
            masterdist = []
            for di in self.id_dpi.distribusi_ids:
                masterdist2 = (0, 0, {'dept': di.dept.id})
                masterdist.append(masterdist2)
            vals={'name': self.name,
                 'dept': self.dept.id,
                 'section': self.section.id,
                 'doc_no': self.doc_no,
                 'content': self.content,
                 'parent_id': self.parent_id.id,
                 }
            dp_ids.write(vals)
            document_distribution_master_obj = self.env['document.distribution.master']
            ddm_ids = document_distribution_master_obj.search([('doc_id_master', '=', self.doc_page.id)]).unlink()
            dp_ids.write({
                 'distribution_ids': masterdist,
                 })
            document_page_history_obj = self.env['document.page.history']
            dph_ids_list=dp_ids.create_history(self.doc_page.id, self.content, "content", self.doc_no, revision=self.revision)
            distribution = dp_ids.create_distributionmaster_revision_2(dph_ids_list.id,self.id_dpi.distribution_ids)
            attach = []
            for att in self.document_attc1:
                attach.append(att.id)
            dph_ids_list.write({'date_confirm': self.issue_plan, 'lamp': [(6, 0, attach)]})
            dp_ids.page_approval_approved2()
            dp_ids.distribusi_act()
            document_page_in_obj = self.env['document.propose.in']
            model_data_obj = self.env['ir.model.data']
            message_obj = self.env['mail.message']
            subtype_id = model_data_obj.get_object_reference('mail', 'mt_comment')[1]
            message_obj.create(
                {'res_id': self.id_dpi.id,
                 'model': 'document.propose.in',
                 'subtype_id': subtype_id,
                 'body': _('Changes in the document %s has been approved by QMR.') % self.name
                 }
            )
            return self.id_dpi.write({'date_limit': time.strftime('%Y-%m-%d'),'confirm_id': self.env.uid,'state': 'convert','doc_regis_bool':True})
        else:
            raise osv.except_osv(_('Invalid Action!'), _('Please Entry Content Document First!'))

1 个答案:

答案 0 :(得分:1)

'res_id':self.ids [0],或'res_id':self.id_dpi.id ,?最后似乎还可以。

使用此代码:

message_obj.create({
    'res_id': self.id_dpi.id,
    'model': 'document.propose.in',
    'subtype_id': subtype_id,
    'body': _('Changes in the document %s has been approved by QMR.') % self.name
})