- 上传者: Administrator
- 上传时间:2023年11月19日 02时31分41秒
* External IDs and Namespaces ** *** An External ID can be simply defined as a unique identifier used to specify XML records defined. They are also c ......
External IDs and Namespaces
An External ID can be simply defined as a unique identifier used to specify XML records defined. They are also called as XML IDs.These are records of the model ir.model.data which are imported in the case of importing data in Odoo.
When we are importing data using XML IDs, it initially checks for the existence of a record with the same identifier. If there is an existing record with the XML ID, then the UPDATE process will be worked. Otherwise, the CREATE operation will be processed. Usually, XML IDs will be the combination of the record ID and the module name.
E.g., sale.mail_act_sale_upsell
We can update any XML record if the external ID is known. Consider the below as an example.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="base.main_company" model="res.company">
<field name="name">My Company (San Francisco)</field>
</record>
</data>
</odoo>
Here ID of the record is given as XML ID of the main company.Since there is a record with this XML ID, update operation will be performed, resulting in the name changing of the main company.The name field value will be updated to “My Company (San Francisco). There is an option to get the External ID of any records from the User Interface. After enabling debug mode, developer tool menu will be shown. There is an option to see the metadata of the record from here. External ID is shown inside the metadata.
Namespaced phrases are phrases that contain exactly one dot. When using the external ID for a record tag, Odoo first checks if it is namespaced. That is, if it contains exactly one dot. If it is not namespaced, then Odoo adds the module name as the namespace for the record.
Delete Data from XML
So far, we have discussed that we can create or update records using XML. There may be some cases where we need to delete existing records which are previously created at the time of any module installation. Delete tags (<delete>) are useful in such cases.
There are two methods to delete records from XML.
1.Using XML ID
2. Using Search Domain
Using XML ID
We are able to delete previously created records using the XML ID of it. For that, a delete tag is used. The syntax is given below.
<delete model="your model name" id="XML ID of the record"/>
Here, attribute id stands for the external id of the record that needs to be deleted and attribute model is the model of that data. We can only delete records in this way for those records which are previously created using the XML or records which have external ids. Consider an XML record for creating a new Product Category.
<record id="demo_category_1" model="product.category">
<field name="name">Category 1</field>
</record>
To delete this record, you have to follow the steps below.
<delete model = "product.category" id = "demo_category_1"/>
Odoo will search for a record inside the model product.category with the external id on running this code. If it is found, then the record will be deleted. If the record with this external id is not found, Odoo will raise an error.
Using Search Domain
This method helps in using a search domain for finding the record. We are able to pass a domain inside the search attribute of the delete tag. In this case, Odoo checks for matching records with the domain in the specified model while installing the module. The data will be deleted if records are found. In the first method using XML id, an error will be raised if no records are found. But here, no error will be raised if no matching records are found. The syntax is as follows
<delete model = "model_name" search="domain"/>
let us discuss the syntax with an example.
<delete model = "sale.order" search [(partner_id.name,'=','Azure Interior')]/>
By running the above code, Odoo will delete all Sale Orders of the partner whose name is Azure Interior. Commonly delete is rarely used in Odoo.
本文章从网上收集,如有侵权请联系tderp@tderp.com删除
- 微信扫一扫,一分也是爱:
服务原则及地区范围
宜兴通达网络科技有限公司,地处中国宜兴环科园内,是一家高新技术企业。公司在企业网络维护和企业信息化建设与咨询方面,有10多年经验。
我公司愿与客户一道,力求彻底解决客户问题!
我们不是在给企业提供“头痛医头、脚痛医脚”的暂时解决方案,而是在部署根本性安全与稳定服务!!
我们愿携手客户,建立企业IT规划;杜绝随意安装系统、软件等操作;力求共同维护有序、安全、稳定的网络办公环境!!!
IT服务,服务是根本,客户是上帝;我们提供快速响应、快速上门、快速排查,提供优质高效的服务!!!!
通达科技提供全国范围内的服务,服务形式包括远程协助、电话咨询、电子邮件咨询、传真咨询、问答平台的问题解决等。
宜兴地区提供上门服务:
- 市区服务:宜城街道、城北街道(屺亭街道)、新街街道、新庄街道、环科园、渚桥开发区
- 市郊服务:张渚镇、西渚镇、太华镇、徐舍镇、官林镇、杨巷镇、新建镇、和桥镇、高塍镇、万石镇、周铁镇、芳桥镇、丁蜀镇、湖父镇。