Commit 8c1d8ccb by 夏超

[add] 新增返修单自动创建工单功能

parent 380061eb
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import models from . import models
from . import controllers
from . import wizard
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
'name': '融科-玖姿机械', 'name': '融科-玖姿机械',
'version': '14.0', 'version': '14.0',
'category': 'mes', 'category': 'mes',
'depends': ['roke_mes_purchase','roke_mes_sale','roke_mes_documents', 'roke_mes_stock', 'roke_mes_workshop_inspect'], 'depends': ['roke_mes_purchase', 'roke_mes_sale', 'roke_mes_documents', 'roke_mes_stock', 'roke_workstation_api',
'roke_mes_workshop_inspect', 'roke_mes_quality'],
'author': 'www.rokedata.com', 'author': 'www.rokedata.com',
'website': 'http://www.rokedata.com', 'website': 'http://www.rokedata.com',
'description': """ 'description': """
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
'security/ir.model.access.csv', 'security/ir.model.access.csv',
'views/inherit_roke_mes_stock_picking_views.xml', 'views/inherit_roke_mes_stock_picking_views.xml',
'views/inherit_roke_production_task.xml', 'views/inherit_roke_production_task.xml',
'views/inherit_repair_view.xml',
'views/button_js.xml', 'views/button_js.xml',
'views/iniherit_work_order_view.xml', 'views/iniherit_work_order_view.xml',
'views/roke_work_log_views.xml', 'views/roke_work_log_views.xml',
......
from . import inherit_production
from . import inherit_product_task
from odoo import models, fields, api, http, SUPERUSER_ID, _
from odoo.addons.roke_workstation_api.controllers.product_task import RokeWorkstationProductionTask
import logging
import math
_logger = logging.getLogger(__name__)
class JzjxInheritRokeWorkstationProductionTask(RokeWorkstationProductionTask):
@http.route('/roke/workstation/product_task/machine_get_list', type='json', auth='user', csrf=False, cors="*")
def product_task_machine_get_list(self):
"""
获取当前用户权限下所有任务的数据
workstation_id: int 工位ID
limit: int 条数
page: int 页数
"""
_self = http.request
workstation_id = _self.jsonrequest.get("workstation_id", False)
limit = _self.jsonrequest.get("limit", 20)
page = _self.jsonrequest.get("page", 1)
if not workstation_id:
return {"code": 1, "message": f"入参错误! “工位ID”为必传数据。", "data": []}
workstation = _self.env["roke.work.center"].search(
[("id", "=", workstation_id)])
if not workstation:
return {"code": 1, "message": "校验错误! 未找到该工位数据。", "data": []}
user_id = _self.env['roke.employee'].search(
[('user_id', '=', http.request.uid)], limit=1)
process_ids = _self.env['roke.process'].search(
[('workstation_ids', '=', workstation_id)])
# process_list = list(set(process_ids.ids) & set(user_id.process_ids.ids))
process_list = process_ids.ids
domain = [
("task_id.workshop_id", "=", workstation.workshop_id.id),
("process_id", "in", process_list),
("state", "in", ["未完工", "暂停"])
]
work_order = _self.env["roke.work.order"].search(domain)
sql = f"""
SELECT id, type, create_date
FROM (
SELECT roke_production_task.id, 'task' as "type", roke_production_task.create_date
FROM roke_production_task LEFT JOIN roke_work_order on roke_work_order.task_id = roke_production_task.id
WHERE roke_work_order.id in ({" , ".join([f"{v}" for v in work_order.ids])})
and roke_production_task.state in ('未完工', '暂停')
union all
SELECT id, 'work' as "type", create_date
FROM roke_work_order
WHERE type = '返修'
and process_id in ({" , ".join([f"{v}" for v in process_list])})
and state = '未完工'
and repair_task_id is not null
) as task_repair_work
ORDER BY create_date desc
LIMIT {limit}
offset {(page - 1) * limit}
"""
_self.env.cr.execute(sql)
results = _self.env.cr.dictfetchall()
count_sql = f"""
SELECT count(id)
FROM (
SELECT roke_production_task.id
FROM roke_production_task LEFT JOIN roke_work_order on roke_work_order.task_id = roke_production_task.id
WHERE roke_work_order.id in ({" , ".join([f"{v}" for v in work_order.ids])})
and roke_production_task.state in ('未完工', '暂停')
union all
SELECT id
FROM roke_work_order
WHERE type = '返修'
and process_id in ({" , ".join([f"{v}" for v in process_list])})
and state = '未完工'
and repair_task_id is not null
) as task_repair_work
"""
_self.env.cr.execute(count_sql)
task_count = _self.env.cr.dictfetchall()[0].get("count", 0)
ids_list = []
task_id_list = []
work_id_list = []
for v in results:
data_type = v.get("type", '')
data_id = v.get("id", 0)
ids_list.append([data_id, data_type])
if data_type == 'task':
task_id_list.append(data_id)
if data_type == 'work':
work_id_list.append(data_id)
task_ids = _self.env["roke.production.task"].search([("id", "in", task_id_list)])
work_ids = _self.env["roke.work.order"].search([("id", "in", work_id_list)])
task_data_dict = {}
for v in task_ids:
task_data_dict[str(v.id)] = {
"id": v.id,
"code": v.code,
"state": v.state,
"partner": {"id": v.customer_id.id or None, "name": v.customer_id.name or ""},
"plan_qty": v.plan_qty or 0,
"product": {"id": v.product_id.id or None, "name": v.product_id.name or ""},
"priority": v.priority,
"planned_start_time": v.plan_start_date.strftime('%Y-%m-%d') if v.plan_start_date else "",
"plan_date": v.plan_date.strftime('%Y-%m-%d') if v.plan_date else "",
"specification": v.product_id.specification or "",
"model": v.product_id.model or "",
"order_type": "task"
}
work_data_dict = {}
for v in work_ids:
work_data_dict[str(v.id)] = {
"id": v.id,
"code": v.code,
"state": v.state,
"partner": {"id": v.customer_id.id or None, "name": v.customer_id.name or ""},
"plan_qty": v.plan_qty or 0,
"product": {"id": v.product_id.id or None, "name": v.product_id.name or ""},
"priority": v.priority,
"planned_start_time": v.planned_start_time.strftime('%Y-%m-%d') if v.planned_start_time else "",
"plan_date": v.plan_date.strftime('%Y-%m-%d') if v.plan_date else "",
"specification": v.product_id.specification or "",
"model": v.product_id.model or "",
"order_type": "work"
}
data = []
for v in ids_list:
l_id = v[0]
l_type = v[1]
if l_type == "task":
task_data = task_data_dict.get(str(l_id), False)
if not task_data:
continue
data.append(task_data)
if l_type == "work":
work_data = work_data_dict.get(str(l_id), False)
if not work_data:
continue
data.append(work_data)
return {"code": 0, "message": "获取成功!", "data": data, "process_ids": process_list, "count": task_count}
from odoo import models, fields, api, http, SUPERUSER_ID, _
from odoo.addons.roke_mes_quality.controller.inherit_production import InheritProduction
import logging
import math
_logger = logging.getLogger(__name__)
class JzjxInheritProduction(InheritProduction):
def _get_work_record_values(self, wo, values):
"""
获取创建工单需要的数据:报工采集结果
scrap_qty:报废数
repair_qty:返修数
scrap_list:报废明细---->[{"reason_id": 报废原因ID, "qty": 报废数量}]
repair_list:返修明细---->[{"reason_id": 返修原因ID, "qty": 返修数量}]
:param wo: 工单
:param values: 入参
:return:
"""
res = super(JzjxInheritProduction, self)._get_work_record_values(wo, values)
repair_product_id = values.get('process_id', False) # 工序
if repair_product_id:
res.update({"repair_product_id": repair_product_id})
return res
...@@ -2,3 +2,5 @@ from . import inherit_roke_work_order ...@@ -2,3 +2,5 @@ from . import inherit_roke_work_order
from . import inherit_production_task from . import inherit_production_task
from . import inherit_workcenter from . import inherit_workcenter
from . import work_log from . import work_log
from . import inherit_res_config_settings
from . import inheirt_roke_repair_order
import logging
from . import generator
from odoo import models, fields, api, _
_logger = logging.getLogger(__name__)
class JzjxInheritRepairOrder(models.Model):
_inherit = "roke.repair.order"
is_refix_auto_work_order = fields.Boolean(string="是否自动生产返修单")
class JzjxInheritRepairOrderLine(models.Model):
_inherit = "roke.repair.order.line"
repair_work_order_id = fields.Many2one("roke.work.order", string="返修工单")
is_refix_auto_work_order = fields.Boolean(string="是否自动生产返修单")
class JzjxInheritWorkOrder(models.Model):
_inherit = "roke.work.order"
def write(self, vals):
id_dict = {}
for v in self:
id_dict[str(v.id)] = v.state
res = super(JzjxInheritWorkOrder, self).write(vals)
for v in self:
old_state = id_dict.get(str(v.id), "")
if "state" not in vals.keys():
return res
state = vals.get("state", "")
if state in ["已完工", "强制完成"]:
repair_order_id = self.env["roke.repair.order.line"].sudo().search([
("repair_work_order_id", "=", self.id)], limit=1)
if repair_order_id:
repair_order_id.write({"state": "返修完成"})
repair_order_id.order_id.write({"state": "返修完成"})
if state == "未完工" and old_state in ["暂停", "强制完工", "已完工"]:
repair_order_id = self.env["roke.repair.order.line"].sudo().search([
("repair_work_order_id", "=", self.id)], limit=1)
if repair_order_id:
repair_order_id.write({"state": "返修中"})
repair_order_id.order_id.write({"state": "返修中"})
return res
from odoo import models, fields, api
from odoo.exceptions import UserError, ValidationError
class JzjxInheritConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
refix_auto_work_order = fields.Boolean(string="返修自动生产工单", default=False)
@api.model
def get_values(self):
res = super(JzjxInheritConfigSettings, self).get_values()
refix_auto_work_order = self.env['ir.config_parameter'].sudo().get_param("refix_auto_work_order")
res.update(
refix_auto_work_order=refix_auto_work_order
)
return res
def set_values(self):
super(JzjxInheritConfigSettings, self).set_values()
self.env['ir.config_parameter'].sudo().set_param('refix_auto_work_order', self.refix_auto_work_order)
def get_refix_params(self):
return self.refix_auto_work_order
...@@ -6,3 +6,4 @@ class InheritWorkOrder(models.Model): ...@@ -6,3 +6,4 @@ class InheritWorkOrder(models.Model):
document_ids = fields.Many2many(related="task_id.document_ids", string="作业指导") document_ids = fields.Many2many(related="task_id.document_ids", string="作业指导")
task_file_ids = fields.Many2many(related="task_id.file_ids") task_file_ids = fields.Many2many(related="task_id.file_ids")
repair_task_id = fields.Many2one('roke.production.task', string="返修上级任务")
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="inherit_view_roke_repair_order_form" model="ir.ui.view">
<field name="name">inherit.roke.repair.order.form</field>
<field name="model">roke.repair.order</field>
<field name="inherit_id" ref="roke_mes_quality.view_roke_repair_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='line_ids']/tree//field[@name='wr_id']" position="after">
<field name="repair_work_order_id" options="{'no_create': True}"/>
</xpath>
<xpath expr="//field[@name='line_ids']/tree//button[@name='execute_repair']" position="replace">
<field name="is_refix_auto_work_order" invisible="1"/>
<button name="execute_repair" type="object" string="执行返修" class="oe_highlight"
attrs="{'invisible': ['|', ('allow_qty', '&lt;=', 0), ('is_refix_auto_work_order', '=', True)]}"/>
</xpath>
<xpath expr="//button[@name='multi_execute_repair']" position="replace">
<field name="is_refix_auto_work_order" invisible="1"/>
<button name="multi_execute_repair" type="object" string="批量执行返修" class="oe_highlight"
attrs="{'invisible': ['|', ('state', 'in', ['取消', '待确认', '返修完成']), '|',
('can_repair', '!=', True), ('is_refix_auto_work_order', '=', True)]}"/>
</xpath>
</field>
</record>
<record id="inherit_view_roke_repair_order_line_form" model="ir.ui.view">
<field name="name">inherit.roke.repair.order.line.form</field>
<field name="model">roke.repair.order.line</field>
<field name="inherit_id" ref="roke_mes_quality.view_roke_repair_order_line_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='product_id']" position="after">
<field name="repair_work_order_id" options="{'no_create': True}"/>
</xpath>
<xpath expr="//button[@name='execute_repair']" position="replace">
<field name="is_refix_auto_work_order" invisible="1"/>
<button name="execute_repair" type="object" string="执行返修" class="oe_highlight"
attrs="{'invisible': ['|', ('allow_qty', '&lt;=', 0), ('is_refix_auto_work_order', '=', True)]}"/>
</xpath>
</field>
</record>
<record id="inherit_view_roke_repair_order_line_tree" model="ir.ui.view">
<field name="name">inherit.roke.repair.order.line.tree</field>
<field name="model">roke.repair.order.line</field>
<field name="inherit_id" ref="roke_mes_quality.view_roke_repair_order_line_tree"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='execute_repair']" position="replace">
<field name="is_refix_auto_work_order" invisible="1"/>
<button name="execute_repair" type="object" string="执行返修" class="oe_highlight"
attrs="{'invisible': ['|', ('allow_qty', '&lt;=', 0), ('is_refix_auto_work_order', '=', True)]}"/>
</xpath>
</field>
</record>
</odoo>
\ No newline at end of file
...@@ -48,4 +48,25 @@ ...@@ -48,4 +48,25 @@
</xpath> </xpath>
</field> </field>
</record> </record>
<record id="jzjx_inherit_config_settings_form" model="ir.ui.view">
<field name="name">jzjx.inherit.config.settings.form.view</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="roke_mes_production.roke_mes_production_inherit_config_settings_form_view"/>
<field name="arch" type="xml">
<xpath expr="//div[@id='production_setting_main']" position="inside">
<div class="col-12 col-lg-6 o_setting_box" title="返修自动生产工单" id="refix_auto_work_order">
<div class="o_setting_left_pane">
<field name="refix_auto_work_order"/>
</div>
<div class="o_setting_right_pane">
<label for="refix_auto_work_order"/>
<div class="text-muted">
勾选后,自动生成工单,将返修前置工单和当前生成工单绑定在返修单中。
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo> </odoo>
\ No newline at end of file
from . import inherit_roke_create_work_record_wizard
import datetime
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class InheritRokeCreateWorkRecordWizard(models.TransientModel):
_inherit = "roke.create.work.record.wizard"
repair_product_id = fields.Many2one("roke.process", string="工序")
def create_other_order(self, new_record):
"""
创建报废单、返修单
生产返修工单
:return:
"""
res = super(InheritRokeCreateWorkRecordWizard, self).create_other_order(new_record)
repair = res.get("repair", False)
refix_params = self.env['ir.config_parameter'].sudo().get_param("refix_auto_work_order")
if repair and self.repair_qty and (refix_params == "True" or refix_params is True) and self.repair_product_id:
repair.is_refix_auto_work_order = refix_params == "True" or refix_params is True
for v in repair.line_ids:
repair_work_order_id = self.env["roke.work.order"].create({
"process_id": new_record.process_id.id,
"product_id": self.repair_product_id.id,
"plan_qty": v.qty,
"sequence": 1,
"planned_start_time": datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
"plan_date": datetime.datetime.now().strftime('%Y-%m-%d') + " 23:59:59",
"repair_task_id": new_record.pt_id.id or repair.wo_id.repair_task_id.id,
"type": "返修"
})
data = {
"repair_work_order_id": repair_work_order_id,
"is_refix_auto_work_order": refix_params == "True" or refix_params is True
}
if repair_work_order_id.wo_start_state == '已开工':
data.update({"state": "返修中"})
repair.write({"state": "返修中"})
v.write(data)
return res
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