[IMP] base: simplify _xmlid_lookup cache
The _xmlid_lookup cache contains the id of the ir.model.data with is unused, making cache pupulation and usage more complex than needed. Removing this id in prevision of the next commit Part-of: odoo/odoo#129029
This commit is contained in:
@@ -24,7 +24,7 @@ class ProductMargin(models.TransientModel):
|
||||
|
||||
def ref(xml_id):
|
||||
proxy = self.env['ir.model.data']
|
||||
return proxy._xmlid_lookup(xml_id)[2]
|
||||
return proxy._xmlid_lookup(xml_id)[1]
|
||||
|
||||
search_view_id = ref('product.product_search_form_view')
|
||||
graph_view_id = ref('product_margin.view_product_margin_graph')
|
||||
|
||||
@@ -430,13 +430,13 @@ class PurchaseOrder(models.Model):
|
||||
ir_model_data = self.env['ir.model.data']
|
||||
try:
|
||||
if self.env.context.get('send_rfq', False):
|
||||
template_id = ir_model_data._xmlid_lookup('purchase.email_template_edi_purchase')[2]
|
||||
template_id = ir_model_data._xmlid_lookup('purchase.email_template_edi_purchase')[1]
|
||||
else:
|
||||
template_id = ir_model_data._xmlid_lookup('purchase.email_template_edi_purchase_done')[2]
|
||||
template_id = ir_model_data._xmlid_lookup('purchase.email_template_edi_purchase_done')[1]
|
||||
except ValueError:
|
||||
template_id = False
|
||||
try:
|
||||
compose_form_id = ir_model_data._xmlid_lookup('mail.email_compose_message_wizard_form')[2]
|
||||
compose_form_id = ir_model_data._xmlid_lookup('mail.email_compose_message_wizard_form')[1]
|
||||
except ValueError:
|
||||
compose_form_id = False
|
||||
ctx = dict(self.env.context or {})
|
||||
@@ -792,7 +792,7 @@ class PurchaseOrder(models.Model):
|
||||
def _send_reminder_open_composer(self,template_id):
|
||||
self.ensure_one()
|
||||
try:
|
||||
compose_form_id = self.env['ir.model.data']._xmlid_lookup('mail.email_compose_message_wizard_form')[2]
|
||||
compose_form_id = self.env['ir.model.data']._xmlid_lookup('mail.email_compose_message_wizard_form')[1]
|
||||
except ValueError:
|
||||
compose_form_id = False
|
||||
ctx = dict(self.env.context or {})
|
||||
|
||||
@@ -678,7 +678,7 @@ class WebsiteForum(WebsiteProfile):
|
||||
vote_ids = Vote.search([('user_id', '=', user.id)])
|
||||
|
||||
# activity by user.
|
||||
comment = Data._xmlid_lookup('mail.mt_comment')[2]
|
||||
comment = Data._xmlid_lookup('mail.mt_comment')[1]
|
||||
activities = Activity.search(
|
||||
[('res_id', 'in', (user_question_ids + user_answer_ids).ids), ('model', '=', 'forum.post'),
|
||||
('subtype_id', '!=', comment)],
|
||||
|
||||
@@ -2014,10 +2014,10 @@ class IrModelData(models.Model):
|
||||
Return (id, res_model, res_id) or raise ValueError if not found
|
||||
"""
|
||||
module, name = xmlid.split('.', 1)
|
||||
query = "SELECT id, model, res_id FROM ir_model_data WHERE module=%s AND name=%s"
|
||||
query = "SELECT model, res_id FROM ir_model_data WHERE module=%s AND name=%s"
|
||||
self.env.cr.execute(query, [module, name])
|
||||
result = self.env.cr.fetchone()
|
||||
if not (result and result[2]):
|
||||
if not (result and result[1]):
|
||||
raise ValueError('External ID not found in the system: %s' % xmlid)
|
||||
return result
|
||||
|
||||
@@ -2025,7 +2025,7 @@ class IrModelData(models.Model):
|
||||
def _xmlid_to_res_model_res_id(self, xmlid, raise_if_not_found=False):
|
||||
""" Return (res_model, res_id)"""
|
||||
try:
|
||||
return self._xmlid_lookup(xmlid)[1:3]
|
||||
return self._xmlid_lookup(xmlid)
|
||||
except ValueError:
|
||||
if raise_if_not_found:
|
||||
raise
|
||||
@@ -2040,7 +2040,7 @@ class IrModelData(models.Model):
|
||||
def check_object_reference(self, module, xml_id, raise_on_access_error=False):
|
||||
"""Returns (model, res_id) corresponding to a given module and xml_id (cached), if and only if the user has the necessary access rights
|
||||
to see that object, otherwise raise a ValueError if raise_on_access_error is True or returns a tuple (model found, False)"""
|
||||
model, res_id = self._xmlid_lookup("%s.%s" % (module, xml_id))[1:3]
|
||||
model, res_id = self._xmlid_lookup("%s.%s" % (module, xml_id))
|
||||
#search on id found in result to check if current user has read access right
|
||||
if self.env[model].search([('id', '=', res_id)]):
|
||||
return model, res_id
|
||||
@@ -2114,6 +2114,7 @@ class IrModelData(models.Model):
|
||||
try:
|
||||
self.env.cr.execute(query, [arg for row in sub_rows for arg in row])
|
||||
self.env.registry.clear_cache()
|
||||
|
||||
except Exception:
|
||||
_logger.error("Failed to insert ir_model_data\n%s", "\n".join(str(row) for row in sub_rows))
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user