Odooers论坛

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Unable to remove fields created by Studio

形象
odoo
3 注释
形象
丢弃
形象
odoo
-

Cybrosys, thank you very much for the detailed explination. Some research on Google I dead previously also mentioned this but I was unsure if changing them from Base Fields to Custom Field wouldn't mess up the DB.

Must be doing something wrong: ValueError: <class 'psycopg2.errors.UndefinedColumn'>: "column "x_studio_float_field_1hwuy" does not exist

形象
odoo
-

My bad, rookie mistake, I did not understand that "Field name" and "ID" were not the same.

To find the ID's, I exported the fields along with their ID. Is there a more efficient way?

Why do some Custom Fields suddenly become Base Fields?

形象
odoo
-

The id will be available in the URL when you open the form view of the field(The one you have shared in the image). If you need to remove the fields by name, just change the domain. The id will be unique in the table. If you use the name of a field, there is a possibility of having more fields with the same name(in different models). But, in your case it is not an issue(Please use this method for only removing the fields added using Studio.). For example,

query = "UPDATE ir_model_fields set state = 'manual' WHERE name = 'x_studio_float_field_1hwuy';"

env.cr.execute(query)
base_fields = model.sudo().search([('name', '=', 'x_studio_float_field_1hwuy')])

base_fields.sudo().unlink()

Regarding the state of the fields: the model 'product.product'(model for product variants) inherits model 'product.template'(model for product). As mentioned earlier, the Odoo Studio created that base field. The one you have created will be there as a custom field(in 'product.template').

1 答案
0
形象
odoo
最佳答案

Hi,

You cannot delete those fields since they are Base Fields. If you need to remove any fields, the first step is to remove the field from the view using studio(you have added it from studio) and then delete the field. But, in this case, you have to change the state of the fields from 'base' to 'manual' before deleting. i.e, you have to convert the Base Field to a Custom Field. You can do this by running a query from a scheduled action. For example if the ids of the fields to remove are 28341 and 28342 we can use the code below:

query = "UPDATE ir_model_fields set state = 'manual' WHERE id in (28341, 28342);"
env.cr.execute(query)
base_fields = model.sudo().search([('id', 'in', (28341, 28342))])
base_fields.sudo().unlink()

Here the first 2 lines are used to run the query to change the state of the fields. The next 2 lines are used to remove the fields.
Add this code in a scheduled action, where the model should be selected as Fields(ir.model.fields) and run it.

An additional case: the field that you have added here looks like it was added from the Product Template form view(that field is added in the Product Variant as a related field by Studio). So, you have to do an additional step. i.e, remove the field x_studio_float_field_1HwUy from the product.template model first. Then you can remove it from the product.product. For both steps, you can use the scheduled action with the code given above. You just have to provide the field ids.

Regards

形象
丢弃