Commit 3a0cf43b by nningxx

添加筛选以及接口

parent 73acc600
......@@ -20,7 +20,7 @@
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['base'],
'depends': ['roke_mes_three_colour_light'],
# always loaded
'data': [
......
# -*- coding: utf-8 -*-
# from odoo import http
# class ThtProject(http.Controller):
# @http.route('/tht_project/tht_project/', auth='public')
# def index(self, **kw):
# return "Hello, world"
# @http.route('/tht_project/tht_project/objects/', auth='public')
# def list(self, **kw):
# return http.request.render('tht_project.listing', {
# 'root': '/tht_project/tht_project',
# 'objects': http.request.env['tht_project.tht_project'].search([]),
# })
# @http.route('/tht_project/tht_project/objects/<model("tht_project.tht_project"):obj>/', auth='public')
# def object(self, obj, **kw):
# return http.request.render('tht_project.object', {
# 'object': obj
# })
from odoo import http
from odoo.http import request
from odoo.addons.roke_mes_three_colour_light.controller.main import RokeMesThreeColourLight
import os
from jinja2 import Environment, FileSystemLoader
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
templateloader = FileSystemLoader(searchpath=BASE_DIR + "/static/src/view")
env = Environment(loader=templateloader)
class RokeMesThreeColourLightExt(RokeMesThreeColourLight):
#重写
@http.route("/roke/three_color_light/device_state_list", type="http", auth='none', cors='*', csrf=False)
def device_state_list(self, **kwargs):
# 自定义逻辑
_self = request
factory_code = "custom_factory_code_123" # 自定义 factory_code
data = {
"code": 1,
"message": "请求通过",
"data": {
"factory_code": factory_code,
"override": True # 添加额外字段
}
}
template = env.get_template('equipment_status.html')
return template.render(data)
@http.route('/roke/equipment/search', type='json', methods=['POST', 'OPTIONS'], auth="none", csrf=False,
cors='*')
def search_equipment(self):
"""
根据 plant_id category_id 查询设备(JSON POST)
请求示例:
{
"plant_name": ,
"category_name":
}
"""
# 获取请求数据
data = http.request.jsonrequest
plant_name = data.get('plant_name')
category_name = data.get('category_name')
data_acquisition_code = data.get('data_acquisition_code')
domain = []
if data_acquisition_code:
domain.append(('data_acquisition_code', 'in', data_acquisition_code))
# 构建查询条件
if plant_name:
domain.append(('plant_id.name', '=', plant_name))
if category_name:
domain.append(('category_id.name', '=', category_name))
if not domain:
return {
"state": "error",
"msgs": "参数不全;车间和 设备类别不能同时为空",
"data": []
}
# 查询设备
equipments = http.request.env['roke.mes.equipment'].sudo().search(domain)
# 构造响应数据
equipment_list = [{
'id': eq.id,
'device_name': eq.name,
'device_code': eq.code,
'data_acquisition_code': eq.data_acquisition_code,
'category': eq.category_id.name if eq.category_id else '',
'plant_name': eq.plant_id.name if eq.plant_id else '',
} for eq in equipments]
return {
'status': 'success',
'code': 200,
'data': equipment_list
}
<odoo>
<data>
<!-- explicit list view definition -->
<!--
<record model="ir.ui.view" id="tht_project.list">
<field name="name">tht_project list</field>
<field name="model">tht_project.tht_project</field>
<record id="view_dws_inherit_roke_mes_equipment_tht_form" model="ir.ui.view">
<field name="name">view_dws_inherit_roke_mes_equipment_tht_form</field>
<field name="model">roke.mes.equipment</field>
<field name="inherit_id" ref="roke_workstation_api.view_dws_inherit_roke_mes_equipment_form"/>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="value"/>
<field name="value2"/>
</tree>
<xpath expr="//field[@name='workshop_id']" position="after">
<field name="data_acquisition_code"/>
</xpath>
</field>
</record>
-->
<!-- actions opening views on models -->
<!--
<record model="ir.actions.act_window" id="tht_project.action_window">
<field name="name">tht_project window</field>
<field name="res_model">tht_project.tht_project</field>
<field name="view_mode">tree,form</field>
</record>
-->
<!-- server action to the one above -->
<!--
<record model="ir.actions.server" id="tht_project.action_server">
<field name="name">tht_project server</field>
<field name="model_id" ref="model_tht_project_tht_project"/>
<field name="state">code</field>
<field name="code">
action = {
"type": "ir.actions.act_window",
"view_mode": "tree,form",
"res_model": model._name,
}
<record id="view_roke_mes_equipment_tree_tht" model="ir.ui.view">
<field name="name">view_roke_mes_equipment_tree_tht</field>
<field name="model">roke.mes.equipment</field>
<field name="inherit_id" ref="roke_mes_equipment.view_roke_mes_equipment_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="data_acquisition_code"/>
</xpath>
<xpath expr="//field[@name='code']" position="attributes">
<attribute name="string">三色灯编号</attribute>
</xpath>
</field>
</record>
-->
<!-- Top menu item -->
<!--
<menuitem name="tht_project" id="tht_project.menu_root"/>
-->
<!-- menu categories -->
<!--
<menuitem name="Menu 1" id="tht_project.menu_1" parent="tht_project.menu_root"/>
<menuitem name="Menu 2" id="tht_project.menu_2" parent="tht_project.menu_root"/>
-->
<!-- actions -->
<!--
<menuitem name="List" id="tht_project.menu_1_list" parent="tht_project.menu_1"
action="tht_project.action_window"/>
<menuitem name="Server to list" id="tht_project" parent="tht_project.menu_2"
action="tht_project.action_server"/>
-->
</data>
</odoo>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment