from dtcloud import models, tools, _, api
import xmltodict
import json
class BaseModel(models.AbstractModel):
_inherit = 'base'
@api.model
def load_views(self, views, options=None):
""" Returns the fields_views of given views, along with the fields of
the current model, and optionally its filters for the given action.
:param views: list of [view_id, view_type]
:param options['toolbar']: True to include contextual actions when loading fields_views
:param options['load_filters']: True to return the model's filters
:param options['action_id']: id of the action to get the filters
:return: dictionary with fields_views, fields and optionally filters
"""
options = options or {}
result = {}
toolbar = options.get('toolbar')
result['fields_views'] = {
v_type: self.fields_view_get(v_id, v_type if v_type != 'list' else 'tree',
toolbar=toolbar if v_type != 'search' else False)
for [v_id, v_type] in views
}
xml_str = result.get('fields_views').get('list').get('arch')
new_xml_str = self.update_arch_result(xml_str)
result.get('fields_views').get('list').update({'arch': new_xml_str})
result['fields'] = self.fields_get()
if options.get('load_filters'):
result['filters'] = self.env['ir.filters'].get_filters(self._name, options.get('action_id'))
return result
def update_arch_result(self, xml_str):
"""
:param xml_str: str树形视图
:return: 新的树形视图结构
"""
new_dict_obj = xmltodict.parse(xml_str, encoding='UTF-8')
json_str = json.dumps(new_dict_obj, ensure_ascii=False)
jsons = json.loads(json_str)
tree_json = jsons.get('tree')
export_xlsx_attr = tree_json.get('@export_xlsx', False)
if not export_xlsx_attr:
tree_json.update({'@export_xlsx': 0})
new_xml_str = xmltodict.unparse(jsons)
new_xml_str = new_xml_str.replace('<?xml version="1.0" encoding="utf-8"?>', '')
return new_xml_str
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示