ValueError: External ID not found in the system: module_name.crm_lead_mail_template

ValueError: External ID not found in the system: module_name.crm_lead_mail_template

我是 odoo 的初学者。谁能帮我找到下面提到的问题的解决方案?

大家好我已经创建了一个电子邮件模板来在该字段更改时触发邮件通知所以我创建了这个函数但是我无法处理这个当我select标记为获胜或任何字段

    lead_status = fields.Many2one("crm.stage","Lead Status",track_visibility='onchange',default=_get_default_lead_status)

    @api.multi
    def write(self, vals):
        if 'lead_status' in vals and self.ids:
            for rec in self:
                template_id =self.env.ref('crm.lead.extended.crm_lead_mail_template').id
                #template = self.env.ref('crm.lead.extended.crm_lead_mail_template')
                #template = self.env.ref('module_name.crm_lead_mail_template')
                template.send_mail(rec.id, force_send=True)          
        return super(crm_extended, self).write(vals)


mail template :
<?xml version="1.0" ?>
<odoo>

    <data noupdate="1">
        <record id="crm_lead_mail_template" model="mail.template">
            <field name="name">CRM-OPPORTUNITY_MODIFIED: Send by email</field>
            <field name="model_id" ref="crm_extended.model_crm_lead_extended"/>
            <field name="email_from">guna19may2015@gmail.com</field>
            <field name="email_to">${object.account_manager.email}</field>
            <field name="subject">Opportunity Record Has Been modified</field>
            <field name="body_html" type="html">
                <div style="margin: 0px; padding: 0px;">
                    <p style="margin: 0px; padding: 0px; font-size: 13px;">
                        Dear ${object.account_manager.display_name} 
                        <br /><br />
                        Opportunity ${object.customer_name.display_name}  has been Modified. . 

                        <br /><br />
                        Thank you


                    </p>
                </div>
            </field>
        </record>
    </data>
</odoo>


when i change select mark as won or any state it shows me below error 

error :
Error:
Odoo Server Error

Traceback (most recent call last):
  File "/opt/odoo/odoo-12.0/odoo/tools/cache.py", line 88, in lookup
    r = d[key]
  File "/opt/odoo/odoo-12.0/odoo/tools/func.py", line 69, in wrapper
    return func(self, *args, **kwargs)
  File "/opt/odoo/odoo-12.0/odoo/tools/lru.py", line 44, in __getitem__
    a = self.d[obj].me
KeyError: ('ir.model.data', <function IrModelData.xmlid_lookup at 0x7f99c64197b8>, 'crm.lead.extended.crm_lead_mail_template')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/odoo/odoo-12.0/odoo/http.py", line 656, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo-12.0/odoo/http.py", line 314, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/opt/odoo/odoo-12.0/odoo/tools/pycompat.py", line 87, in reraise
    raise value
  File "/opt/odoo/odoo-12.0/odoo/http.py", line 698, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo-12.0/odoo/http.py", line 346, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo-12.0/odoo/service/model.py", line 98, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo-12.0/odoo/http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo-12.0/odoo/http.py", line 941, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo-12.0/odoo/http.py", line 519, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/odoo-12.0/addons/web/controllers/main.py", line 966, in call_button
    action = self._call_kw(model, method, args, {})
  File "/opt/odoo/odoo-12.0/addons/web/controllers/main.py", line 954, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo-12.0/odoo/api.py", line 759, in call_kw
    return _call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo/odoo-12.0/odoo/api.py", line 746, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/odoo-12.0/crm_internal_new/crm_extended/models/crm_lead_extended.py", line 122, in action_convert_nurture
    self.write({'lead_status': self.nurture_id})
  File "/opt/odoo/odoo-12.0/crm_internal_new/crm_extended/models/crm_lead_extended.py", line 88, in write
    template_id =self.env.ref('crm.lead.extended.crm_lead_mail_template').id
  File "/opt/odoo/odoo-12.0/odoo/api.py", line 864, in ref
    return self['ir.model.data'].xmlid_to_object(xml_id, raise_if_not_found=raise_if_not_found)
  File "/opt/odoo/odoo-12.0/odoo/addons/base/models/ir_model.py", line 1443, in xmlid_to_object
    t = self.xmlid_to_res_model_res_id(xmlid, raise_if_not_found)
  File "/opt/odoo/odoo-12.0/odoo/addons/base/models/ir_model.py", line 1427, in xmlid_to_res_model_res_id
    return self.xmlid_lookup(xmlid)[1:3]
  File "<decorator-gen-25>", line 2, in xmlid_lookup
  File "/opt/odoo/odoo-12.0/odoo/tools/cache.py", line 93, in lookup
    value = d[key] = self.method(*args, **kwargs)
  File "/opt/odoo/odoo-12.0/odoo/addons/base/models/ir_model.py", line 1416, in xmlid_lookup
    raise ValueError('External ID not found in the system: %s' % xmlid)
ValueError: External ID not found in the system: crm.lead.extended.crm_lead_mail_template



    SOMEONE HELP ME WITH THIS I HAVE TRIED DIFFERENT FUNCTIONS AS BELOW BUT STILL GETTING THE SAME ERROR:

#@api.multi
#def write(self, vals):
    #if 'lead_status' in vals and self.ids:
        #for rec in self:
            #template=self.env.ref('crm_lead_extended.crm_lead_mail_template')
            #template = self.env.ref('mail_template_demo.example_email_template')
            #template = self.env.ref('crm.lead.extended.crm_lead_mail_template')
            #template = self.env.ref('module_name.crm_lead_mail_template')
            #template.send_mail(rec.id, force_send=True)          
    #return super(crm_extended, self).write(vals)

@api.multi
def write(self, vals):
    res = super(crm_extended, self).write(vals)
    if vals.get('lead_status'):
        template_id = self.env.ref('crm_lead_extended.crm_lead_mail_template')
        for lead in self:
            template_id.send_mail(lead.id)
    return res
#@api.multi
#def submit_expenses(self):
    #self.write({'state': 'mgr_approval'})
    #template = self.env.ref('reimbursement.reim_mgr_approve_email_templates')
    #self.env['mail.template'].browse(template.id).send_mail(self.id)
#def crm_send_mail(self):
    #print("send_mail when lead_status changes")
    #template_id =self.env.ref('crm.lead.extended.crm_lead_mail_template').id
    #self.env['mail.template'].browse(template_id).send_mail(self.id,force_send=True)

send_mail方法中使用的外部id错误,必须使用module_name.template_id

正如我在日志错误中看到的,您的模块名称是 crm_extended,模板 ID 是 crm_lead_mail_template,因此您必须使用以下外部 ID 引用模板:

crm_extended.crm_lead_mail_template