增加中控接口返回对工单、计划单属性的改变(状态,时间等)

This commit is contained in:
mgw
2024-02-27 11:42:59 +08:00
parent dfada55cf7
commit fdddf19d13
5 changed files with 62 additions and 15 deletions

View File

@@ -164,6 +164,13 @@ class Manufacturing_Connect(http.Controller):
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
workorder.equipment_id = work_equipment_id workorder.equipment_id = work_equipment_id
workorder.button_start() workorder.button_start()
# 根据工单的实际开始时间修改排程单的开始时间、状态
if workorder.date_start:
request.env['sf.production.plan'].sudo().search([('production_id', '=', production_id)]).write(
{'actual_start_time': workorder.date_start,
'state': 'processing'})
except Exception as e: except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e} res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('button_Work_START error:%s' % e) logging.info('button_Work_START error:%s' % e)
@@ -193,6 +200,19 @@ class Manufacturing_Connect(http.Controller):
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '该工单未开始'} res = {'Succeed': False, 'ErrorCode': 202, 'Error': '该工单未开始'}
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
workorder.button_finish() workorder.button_finish()
# 根据工单的实际结束时间修改排程单的结束时间、状态,同时修改销售订单的状态
if workorder.date_finished:
request.env['sf.production.plan'].sudo().search([('production_id', '=', production_id)]).write(
{'actual_end_time': workorder.date_finished,
'state': 'finished'})
production_obj = request.env['mrp.production'].sudo().search([('name', '=', production_id)])
if production_obj:
production_obj.sudo().schedule_state = '已完成'
production_obj.write({'state': 'completed'})
request.env['sale.order'].sudo().search(
[('name', '=', production_obj.origin)]).write({'schedule_status': 'to deliver'})
except Exception as e: except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e} res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('button_Work_End error:%s' % e) logging.info('button_Work_End error:%s' % e)
@@ -362,7 +382,6 @@ class Manufacturing_Connect(http.Controller):
old_localtion.location_status = '空闲' old_localtion.location_status = '空闲'
old_localtion.production_id = False old_localtion.production_id = False
# return json.JSONEncoder().encode(res) # return json.JSONEncoder().encode(res)
# else: # else:
# res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'} # res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'}

View File

@@ -92,7 +92,9 @@ class MrpProduction(models.Model):
# 新添加的状态逻辑 # 新添加的状态逻辑
if production.state == 'progress' and production.schedule_state == '已排': if production.state == 'progress' and production.schedule_state == '已排':
production.state = 'pending_processing' production.state = 'pending_processing'
elif production.state == 'progress' and production.schedule_state == '已完成': # elif production.state == 'progress' and production.schedule_state == '已完成':
# production.state = 'completed'
elif production.state == 'pending_processing' and production.schedule_state == '已完成':
production.state = 'completed' production.state = 'completed'
def action_check(self): def action_check(self):

View File

@@ -52,10 +52,10 @@ class sf_production_plan(models.Model):
('reverse', '倒排'), ('positive', '顺排')], string='排程设置', default='reverse') ('reverse', '倒排'), ('positive', '顺排')], string='排程设置', default='reverse')
product_id = fields.Many2one('product.product', '关联产品') product_id = fields.Many2one('product.product', '关联产品')
origin = fields.Char(string='订单号') origin = fields.Char(string='订单号')
# 加工时长 # # 加工时长
process_time = fields.Float(string='加工时长', digits=(16, 2)) # process_time = fields.Float(string='加工时长', digits=(16, 2))
# 实际加工时长、实际开始时间、实际结束时间 # 实际加工时长、实际开始时间、实际结束时间
actual_process_time = fields.Float(string='实际加工时长', digits=(16, 2)) actual_process_time = fields.Float(string='实际加工时长(分钟)', digits=(16, 2), compute='_compute_actual_process_time')
actual_start_time = fields.Datetime(string='实际开始时间') actual_start_time = fields.Datetime(string='实际开始时间')
actual_end_time = fields.Datetime(string='实际结束时间') actual_end_time = fields.Datetime(string='实际结束时间')
shift = fields.Char(string='班次') shift = fields.Char(string='班次')
@@ -67,16 +67,25 @@ class sf_production_plan(models.Model):
sequence = fields.Integer(string='序号', copy=False, readonly=True, index=True) sequence = fields.Integer(string='序号', copy=False, readonly=True, index=True)
current_operation_name = fields.Char(string='当前工序名称', size=64, default='生产计划') current_operation_name = fields.Char(string='当前工序名称', size=64, default='生产计划')
# 计算实际加工时长
@api.depends('actual_start_time', 'actual_end_time')
def _compute_actual_process_time(self):
for item in self:
if item.actual_start_time and item.actual_end_time:
item.actual_process_time = (item.actual_end_time - item.actual_start_time).total_seconds() / 60
else:
item.actual_process_time = None
@api.onchange('production_line_id') @api.onchange('production_line_id')
def _compute_production_line_id(self): def _compute_production_line_id(self):
for item in self: for item in self:
item.sudo().production_id.production_line_id = item.production_line_id.id item.sudo().production_id.production_line_id = item.production_line_id.id
item.sudo().production_id.plan_start_processing_time = item.date_planned_start item.sudo().production_id.plan_start_processing_time = item.date_planned_start
@api.onchange('state') # @api.onchange('state')
def _onchange_state(self): # def _onchange_state(self):
if self.state == 'finished': # if self.state == 'finished':
self.production_id.schedule_state = '已完成' # self.production_id.schedule_state = '已完成'
# @api.model # @api.model
# def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None): # def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):

View File

@@ -66,9 +66,25 @@
<field name="origin"/> <field name="origin"/>
<field name="product_qty"/> <field name="product_qty"/>
<field name="order_deadline"/> <field name="order_deadline"/>
<field name="process_time"/> <!-- <field name="process_time"/> -->
<field name="schedule_setting"/> <field name="schedule_setting"/>
<field name="production_line_id"/> <field name="production_line_id"/>
<!-- Chatter -->
<!-- <div class="oe_chatter"> -->
<!-- <field name="message_follower_ids" widget="mail_followers"/> -->
<!-- <field name="message_ids" widget="mail_thread"/> -->
<!-- <field name="activity_ids"/> -->
<!-- </div> -->
<!-- <div class="oe_chatter"> -->
<!-- <field name="message_follower_ids"/> -->
<!-- <field name="message_ids"/> -->
<!-- </div> -->
</group>
<group string="加工信息">
<field name="date_planned_start"/> <field name="date_planned_start"/>
<field name="date_planned_finished"/> <field name="date_planned_finished"/>
<field name="actual_process_time"/> <field name="actual_process_time"/>
@@ -83,10 +99,7 @@
<!-- <field name="message_ids" widget="mail_thread"/> --> <!-- <field name="message_ids" widget="mail_thread"/> -->
<!-- <field name="activity_ids"/> --> <!-- <field name="activity_ids"/> -->
<!-- </div> --> <!-- </div> -->
<div class="oe_chatter">
<field name="message_follower_ids"/>
<field name="message_ids"/>
</div>
</group> </group>
<!-- <group string="规格信息" col="1"> --> <!-- <group string="规格信息" col="1"> -->
<!-- <group col="3"> --> <!-- <group col="3"> -->
@@ -119,6 +132,10 @@
<!-- <field name="delivery_quantity"/> --> <!-- <field name="delivery_quantity"/> -->
<!-- <field name="delivery_date"/> --> <!-- <field name="delivery_date"/> -->
<!-- </group> --> <!-- </group> -->
<div class="oe_chatter">
<field name="message_follower_ids"/>
<field name="message_ids"/>
</div>
</group> </group>
</sheet> </sheet>
</form> </form>

View File

@@ -310,7 +310,7 @@ class SfShelf(models.Model):
class ShelfLocation(models.Model): class ShelfLocation(models.Model):
_name = 'sf.shelf.location' _name = 'sf.shelf.location'
_description = '货位' _description = '货位'
_order = 'name' _order = 'name, id'
# current_location_id = fields.Many2one('sf.shelf.location', string='当前位置') # current_location_id = fields.Many2one('sf.shelf.location', string='当前位置')
# # 目的位置 # # 目的位置