交期状态开发
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
<searchpanel>
|
||||
<field name="routing_type" select="multi" string="工序类型" icon="fa-building" enable_counters="1"/>
|
||||
<field name="state" select="multi" string="状态" icon="fa-building" enable_counters="1"/>
|
||||
|
||||
<field name="construction_period_status" select="multi" icon="fa-building" enable_counters="1"/>
|
||||
<!-- <field name="manual_quotation" select="multi" string="" icon="fa-building" enable_counters="1"/>-->
|
||||
</searchpanel>
|
||||
|
||||
|
||||
@@ -34,6 +34,65 @@ class MrpProduction(models.Model):
|
||||
tool_state_remark = fields.Text(string='功能刀具状态备注(缺刀)', compute='_compute_tool_state_remark', store=True)
|
||||
tool_state_remark2 = fields.Text(string='功能刀具状态备注(无效刀)', readonly=True)
|
||||
|
||||
def _compute_default_delivery_status(self):
|
||||
need_list = [
|
||||
'pending_cam',
|
||||
'progress',
|
||||
'rework',
|
||||
'scrap',
|
||||
'to_close',
|
||||
]
|
||||
try:
|
||||
if self.state not in need_list:
|
||||
return False
|
||||
if not self.deadline_of_delivery:
|
||||
return '已逾期'
|
||||
hours = self.get_hours_diff()
|
||||
if hours >= 48:
|
||||
return '正常'
|
||||
elif hours > 0 and hours < 48:
|
||||
return '预警'
|
||||
else:
|
||||
return '已逾期'
|
||||
except Exception as e:
|
||||
logging.error("Error processing production ID {}: {}".format(self.id, e))
|
||||
raise e
|
||||
|
||||
@api.depends('state', 'deadline_of_delivery')
|
||||
def _compute_delivery_status(self):
|
||||
need_list = [
|
||||
'pending_cam',
|
||||
'progress',
|
||||
'rework',
|
||||
'scrap',
|
||||
'to_close',
|
||||
]
|
||||
for production in self:
|
||||
production.delivery_status = production._compute_default_delivery_status()
|
||||
|
||||
delivery_status = fields.Selection([('正常', '正常'), ('预警', '预警'), ('已逾期', '已逾期')], string='交期状态',
|
||||
store=True,
|
||||
compute='_compute_delivery_status',
|
||||
default=lambda self: self._compute_default_delivery_status())
|
||||
|
||||
def get_hours_diff(self):
|
||||
# 获取当前日期和时间
|
||||
current_datetime = fields.Datetime.now()
|
||||
|
||||
# 将 date_field 转换为 datetime 对象
|
||||
if self.deadline_of_delivery:
|
||||
date_obj = fields.Date.from_string(self.deadline_of_delivery)
|
||||
# 将 date 对象转换为 datetime 对象,设置时间为 00:00:00
|
||||
date_obj = datetime.datetime.combine(date_obj, datetime.time.min)
|
||||
|
||||
# 计算两个日期之间的差值
|
||||
delta = date_obj - current_datetime
|
||||
|
||||
# 返回差值的小时数
|
||||
return int(delta.total_seconds() / 3600)
|
||||
else:
|
||||
return 0.0
|
||||
|
||||
@api.depends('procurement_group_id.mrp_production_ids.move_dest_ids.group_id.sale_id')
|
||||
def _compute_deadline_of_delivery(self):
|
||||
for production in self:
|
||||
|
||||
@@ -147,6 +147,54 @@ class ResMrpWorkOrder(models.Model):
|
||||
|
||||
tag_type = fields.Selection([("重新加工", "重新加工")], string="标签", tracking=True)
|
||||
|
||||
def _compute_default_construction_period_status(self):
|
||||
need_list = [
|
||||
'progress',
|
||||
'to be detected']
|
||||
try:
|
||||
if self.state not in need_list:
|
||||
return False
|
||||
if not self.date_planned_finished:
|
||||
return '已逾期'
|
||||
hours = self.get_hours_diff()
|
||||
if hours >= 12:
|
||||
return '正常'
|
||||
elif hours > 0 and hours < 12:
|
||||
return '预警'
|
||||
else:
|
||||
return '已逾期'
|
||||
except Exception as e:
|
||||
logging.error("Error processing production ID {}: {}".format(self.id, e))
|
||||
raise e
|
||||
|
||||
@api.depends('state', 'date_planned_finished')
|
||||
def _compute_construction_period_status(self):
|
||||
for worker in self:
|
||||
worker.construction_period_status = worker._compute_default_construction_period_status()
|
||||
|
||||
construction_period_status = fields.Selection([('正常', '正常'), ('预警', '预警'), ('已逾期', '已逾期')], string='工期状态',
|
||||
store=True,
|
||||
compute='_compute_construction_period_status',
|
||||
default=lambda self: self._compute_default_construction_period_status())
|
||||
|
||||
def get_hours_diff(self):
|
||||
# 获取当前日期和时间
|
||||
current_datetime = fields.Datetime.now()
|
||||
|
||||
# 将 date_field 转换为 datetime 对象
|
||||
if self.date_planned_finished:
|
||||
date_obj = fields.Datetime.from_string(self.date_planned_finished)
|
||||
# 将 date 对象转换为 datetime 对象,设置时间为 00:00:00
|
||||
# date_obj = datetime.datetime.combine(date_obj, datetime.time.min)
|
||||
|
||||
# 计算两个日期之间的差值
|
||||
delta = date_obj - current_datetime
|
||||
|
||||
# 返回差值的小时数
|
||||
return int(delta.total_seconds() / 3600)
|
||||
else:
|
||||
return 0.0
|
||||
|
||||
@api.depends('name', 'production_id.name')
|
||||
def _compute_surface_technics_picking_ids(self):
|
||||
for workorder in self:
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
decoration-success="reservation_state == 'assigned'"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='state']" position="before">
|
||||
<field name="production_type" widget="badge" decoration-warning="production_type == '人工线下加工'" decoration-success="production_type == '自动化产线加工'" optional="show"/>
|
||||
<field name="production_type" widget="badge" decoration-warning="production_type == '人工线下加工'"
|
||||
decoration-success="production_type == '自动化产线加工'" optional="show"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='activity_ids']" position="replace">
|
||||
<field name="activity_ids" string="下一个活动" widget="list_activity" optional="hide"/>
|
||||
@@ -56,6 +57,16 @@
|
||||
<!-- <button name="action_view_production_schedule" string="生产排程" type="object" attrs="{'invisible': [('state', 'in', ['draft', 'cancel','已排程','progress','done','to_close'])]}"/> -->
|
||||
<!-- <button name="cancel_plan" string="取消排程" type="object" attrs="{'invisible': [('state', 'in', ['draft', 'cancel','progress','done','to_close','confirmed'])]}"/> -->
|
||||
<!-- </xpath> -->
|
||||
<xpath expr="//field[@name='production_real_duration']" position="before">
|
||||
<field name="delivery_status" optional="show" widget="badge"
|
||||
decoration-success="delivery_status == '正常'"
|
||||
decoration-warning="delivery_status == '预警'"
|
||||
decoration-danger="delivery_status == '已逾期'"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='production_real_duration']" position="attributes">
|
||||
<attribute name="invisible">1</attribute>
|
||||
</xpath>
|
||||
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -348,7 +359,7 @@
|
||||
<page string="工艺设计">
|
||||
<field name="technology_design_ids" widget="one2many">
|
||||
<tree editable="bottom">
|
||||
<field name="sequence" widget="handle" />
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="route_id" context="{'production_id': production_id}"
|
||||
attrs="{'readonly': [('is_auto', '=', True)]}" options="{'no_create': True}"/>
|
||||
<field name="process_parameters_id" attrs="{'readonly': [('is_auto', '=', True)]}"
|
||||
@@ -548,6 +559,7 @@
|
||||
<xpath expr="//search" position="inside">
|
||||
<searchpanel class="account_root">
|
||||
<field name="state" icon="fa-filter" enable_counters="1"/>
|
||||
<field name="delivery_status" icon="fa-filter" enable_counters="1"/>
|
||||
</searchpanel>
|
||||
</xpath>
|
||||
<filter name='todo' position="replace"/>
|
||||
|
||||
@@ -32,8 +32,10 @@
|
||||
</field>
|
||||
<xpath expr="//field[@name='qty_remaining']" position="after">
|
||||
<field name="manual_quotation" optional="show"/>
|
||||
<field name='tag_type' widget="badge"
|
||||
decoration-danger="tag_type == '重新加工'"/>
|
||||
<field name="construction_period_status" optional="show" widget="badge"
|
||||
decoration-success="construction_period_status == '正常'"
|
||||
decoration-warning="construction_period_status == '预警'"
|
||||
decoration-danger="construction_period_status == '已逾期'"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='date_planned_start']" position="replace">
|
||||
<field name="date_planned_start" string="计划开始日期" optional="show"/>
|
||||
@@ -257,11 +259,12 @@
|
||||
</xpath>
|
||||
|
||||
<xpath expr="//header" position="inside">
|
||||
<div class="o_statusbar_buttons"><button name="button_change_env"
|
||||
type="object"
|
||||
string="演示模式"
|
||||
class="btn-primary"
|
||||
groups="sf_manufacturing.group_show_button"/>
|
||||
<div class="o_statusbar_buttons">
|
||||
<button name="button_change_env"
|
||||
type="object"
|
||||
string="演示模式"
|
||||
class="btn-primary"
|
||||
groups="sf_manufacturing.group_show_button"/>
|
||||
</div>
|
||||
</xpath>
|
||||
|
||||
@@ -482,11 +485,11 @@
|
||||
</group>
|
||||
</page>
|
||||
|
||||
<page string="2D加工图纸" attrs="{'invisible': [('routing_type','!=','装夹预调')]}">
|
||||
<page string="2D加工图纸" attrs="{'invisible': [('routing_type','!=','装夹预调')]}">
|
||||
<field name="machining_drawings" widget="adaptive_viewer"/>
|
||||
</page>
|
||||
|
||||
<page string="质检标准" attrs="{'invisible': [('routing_type','!=','装夹预调')]}">
|
||||
<page string="质检标准" attrs="{'invisible': [('routing_type','!=','装夹预调')]}">
|
||||
<field name="quality_standard" widget="adaptive_viewer"/>
|
||||
</page>
|
||||
|
||||
@@ -543,11 +546,11 @@
|
||||
<!-- attrs='{"invisible": ["|","|",("state","!=","progress"),("user_permissions","=",False),("results","=","合格")]}'/>-->
|
||||
<!-- </div>-->
|
||||
</page>
|
||||
<page string="2D加工图纸" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>
|
||||
<page string="2D加工图纸" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>
|
||||
<field name="machining_drawings" widget="adaptive_viewer"/>
|
||||
</page>
|
||||
|
||||
<page string="质检标准" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>
|
||||
<page string="质检标准" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>
|
||||
<field name="quality_standard" widget="adaptive_viewer"/>
|
||||
</page>
|
||||
</xpath>
|
||||
|
||||
Reference in New Issue
Block a user