Commit b6ad440f by 龚桂斌

合并分支 'tht-project' 到 'master'

Tht project

查看合并请求 !13
parents 57791b52 b0a240ed
# -*- coding: utf-8 -*-
from . import controllers
from . import models
\ No newline at end of file
# -*- coding: utf-8 -*-
{
'name': "融科-天合堂",
'summary': """
Short (1 phrase/line) summary of the module's purpose, used as
subtitle on modules listing or apps.openerp.com""",
'description': """
Long description of module's purpose
""",
'author': "My Company",
'website': "http://www.yourcompany.com",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/14.0/odoo/addons/base/data/ir_module_category_data.xml
# for the full list
'category': 'Uncategorized',
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['roke_mes_three_colour_light'],
# always loaded
'data': [
# 'security/ir.model.access.csv',
'views/views.xml',
'views/templates.xml',
'views/plant_working_time_config.xml',
'views/menus.xml',
],
# only loaded in demonstration mode
'demo': [
'demo/demo.xml',
],
}
# -*- coding: utf-8 -*-
from . import controllers
\ No newline at end of file
# -*- coding: utf-8 -*-
from odoo import http
from odoo.http import request
from odoo.addons.roke_mes_three_colour_light.controller.main import RokeMesThreeColourLight
import os
import math
from datetime import datetime, time
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 ThtProject(http.Controller):
@http.route('/tht/get/equipment/working_time', type='json', auth="none", csrf=False, cors='*')
def get_equipment_working_time(self, **kwargs):
"""获取车间工作时间"""
jsonrequest = http.request.jsonrequest
plant_name = jsonrequest.get("plant_name", False)
domain = [("code", "!=", False)]
if plant_name:
domain.append(("plant_id.name", "=", plant_name))
equipment_ids = http.request.env['roke.mes.equipment'].sudo().search(domain)
today = datetime.now()
start_working_time = {}
end_working_time = {}
wait_time = {}
plant_ids = equipment_ids.mapped("plant_id")
for plant_id in plant_ids:
config_id = http.request.env['plant.working.time.config'].sudo().search([("plant_id", "=", plant_id.id)], limit=1)
for item in equipment_ids.filtered(lambda x: x.plant_id == plant_id):
start_hour = math.floor(config_id.start_time)
start_working_time[item.code] = datetime.combine(today, time(start_hour, int((config_id.start_time - start_hour) * 60))).strftime("%Y-%m-%d %H:%M:%S")
end_hour = math.floor(config_id.end_time)
end_working_time[item.code] = datetime.combine(today, time(end_hour, int((config_id.end_time - end_hour) * 60))).strftime("%Y-%m-%d %H:%M:%S")
wait_time[item.code] = config_id.wait_time
return {"state": "success", "msgs": "获取数据成功!",
"start_working_time": start_working_time,
"end_working_time": end_working_time,
"wait_time": wait_time}
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>
<!--
<record id="object0" model="tht_project.tht_project">
<field name="name">Object 0</field>
<field name="value">0</field>
</record>
<record id="object1" model="tht_project.tht_project">
<field name="name">Object 1</field>
<field name="value">10</field>
</record>
<record id="object2" model="tht_project.tht_project">
<field name="name">Object 2</field>
<field name="value">20</field>
</record>
<record id="object3" model="tht_project.tht_project">
<field name="name">Object 3</field>
<field name="value">30</field>
</record>
<record id="object4" model="tht_project.tht_project">
<field name="name">Object 4</field>
<field name="value">40</field>
</record>
-->
</data>
</odoo>
\ No newline at end of file
# -*- coding: utf-8 -*-
from . import models
from . import plant_working_time_config
\ No newline at end of file
# -*- coding: utf-8 -*-
# from odoo import models, fields, api
# class tht_project(models.Model):
# _name = 'tht_project.tht_project'
# _description = 'tht_project.tht_project'
# name = fields.Char()
# value = fields.Integer()
# value2 = fields.Float(compute="_value_pc", store=True)
# description = fields.Text()
#
# @api.depends('value')
# def _value_pc(self):
# for record in self:
# record.value2 = float(record.value) / 100
from odoo import api, fields, models
class PlantWorkingTimeConfig(models.Model):
_name = "plant.working.time.config"
_description = "车间工作时间配置"
plant_id = fields.Many2one("roke.plant", string="车间")
start_time = fields.Float(string="开始时间", default="0")
end_time = fields.Float(string="结束时间", default="0")
color = fields.Selection([
('red', '红'),
('yellow', '黄'),
('green', '绿'),
('blue', '蓝'),
('gray', '灰')
], string="颜色")
wait_time = fields.Float(string="等待时间")
\ No newline at end of file
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_plant_working_time_config_group_user,plant_working_time_config group_user,model_plant_working_time_config,base.group_user,1,1,1,1
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<menuitem id="menu_plant_working_time_config" name="车间工作时间配置"
action="tht_project.action_plant_working_time_config"
parent="roke_mes_three_colour_light.roke_three_color_light_iframe_device_monitor_menu"
sequence="40"
groups="base.group_system"
/>
</odoo>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_plant_working_time_config_tree" model="ir.ui.view">
<field name="name">view_plant_working_time_config_tree</field>
<field name="model">plant.working.time.config</field>
<field name="arch" type="xml">
<tree>
<field name="plant_id"/>
<field name="start_time" widget="float_time"/>
<field name="end_time" widget="float_time"/>
</tree>
</field>
</record>
<record id="view_plant_working_time_config_form" model="ir.ui.view">
<field name="name">view_plant_working_time_config_form</field>
<field name="model">plant.working.time.config</field>
<field name="arch" type="xml">
<form>
<group col="3">
<group>
<field name="plant_id"/>
</group>
<group>
<field name="start_time" widget="float_time"/>
</group>
<group>
<field name="end_time" widget="float_time"/>
</group>
</group>
<notebook>
<page string="停机规则设置">
<div class="mb16" style="display: flex; flex-direction: row; align-items: center;">
<div class="ml16" style="width: 150px">
<field name="color"/>
</div>
<span class="ml16">色下连续超过</span>
<div class="ml16" style="width: 150px">
<field name="wait_time"/>
</div>
<span class="ml16">分钟,页面展示停机状态。</span>
</div>
</page>
</notebook>
</form>
</field>
</record>
<record id="action_plant_working_time_config" model="ir.actions.act_window">
<field name="name">车间工作时间配置</field>
<field name="res_model">plant.working.time.config</field>
<field name="view_mode">tree,form</field>
<field name="type">ir.actions.act_window</field>
<field name="domain">[]</field>
<field name="context">{}</field>
</record>
</odoo>
\ No newline at end of file
<odoo>
<data>
<!--
<template id="listing">
<ul>
<li t-foreach="objects" t-as="object">
<a t-attf-href="#{ root }/objects/#{ object.id }">
<t t-esc="object.display_name"/>
</a>
</li>
</ul>
</template>
<template id="object">
<h1><t t-esc="object.display_name"/></h1>
<dl>
<t t-foreach="object._fields" t-as="field">
<dt><t t-esc="field"/></dt>
<dd><t t-esc="object[field]"/></dd>
</t>
</dl>
</template>
-->
</data>
</odoo>
\ No newline at end of file
<odoo>
<data>
<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">
<xpath expr="//field[@name='workshop_id']" position="after">
<field name="data_acquisition_code"/>
</xpath>
</field>
</record>
<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>
</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