优化工艺确认

This commit is contained in:
jinling.yang
2024-11-07 17:59:28 +08:00
parent 01df55ef35
commit d419efa3c3
5 changed files with 79 additions and 22 deletions

View File

@@ -254,6 +254,44 @@ class MrpProduction(models.Model):
if production.tool_state == '2':
production.state = 'rework'
def technology_confirm(self):
# 判断同一个加工面的标准工序的顺序是否依次排序
technology_design = self.technology_design_ids.sorted(key=lambda m: m.sequence)
current_design_index = None
for index, design in enumerate(technology_design.filtered(lambda a: a.routing_tag == 'standard')):
if design == current_design:
current_design_index = index
break # 找到了 current_design跳出循环
# 现在我们有了 current_design 的索引,我们可以找到下一条设计
if current_design_index is not None and current_design_index + 1 < len(technology_design):
next_design = technology_design[current_design_index + 1]
# 下一条设计是 next_design
else:
# 如果 current_design_index 为 None 或者没有下一条设计,则 next_design 为 None
next_design = None
for design in technology_design.filtered(lambda a: a.routing_tag == 'standard'):
routing_type = design.route_id.routing_type
if routing_type in ['装夹预调', 'CNC加工', '解除装夹']:
# standard_designs = [d for d in technology_design_ids if d.routing_tag == 'standard']
# last_design = technology_design[technology_design.index(design) - 1]
next_design = technology_design[2]
for next_design in technology_design:
next_design_routing_type = next_design.route_id.routing_type
logging.info('next_design:%s' % next_design.route_id.name)
logging.info('next_design面:%s' % next_design.panel)
logging.info('design:%s' % design.route_id.name)
logging.info('design面:%s' % design.panel)
if next_design == design:
break
if design.panel != next_design.panel and routing_type not in ['解除装夹']:
raise UserError('【加工面】为%s的标准工序里含有其他加工面的工序,请调整后重试' % design.panel)
if design.panel == next_design.panel:
if (routing_type == '装夹预调' and next_design_routing_type == '解除装夹') or (
routing_type == 'CNC加工' and next_design_routing_type == '装夹预调'):
raise UserError('【加工面】为%s的标准工序顺序有误,请调整后重试' % design.panel)
return True
def action_check(self):
"""
审核启用

View File

@@ -14,7 +14,7 @@ class ResMrpRoutingWorkcenter(models.Model):
('表面工艺', '表面工艺')
], string="工序类型")
routing_tag = fields.Selection([
('Standard', '标准'),
('standard', '标准'),
('special', '特殊')
], string="标签")
is_repeat = fields.Boolean('重复', default=False)
@@ -23,6 +23,7 @@ class ResMrpRoutingWorkcenter(models.Model):
bom_id = fields.Many2one('mrp.bom', required=False)
surface_technics_id = fields.Many2one('sf.production.process', string="表面工艺")
reserved_duration = fields.Float('预留时长', default=30, tracking=True)
def get_no(self):
international_standards = self.search(
[('code', '!=', ''), ('active', 'in', [True, False])],
@@ -79,3 +80,13 @@ class ResMrpRoutingWorkcenter(models.Model):
else:
workcenter_id = workcenter_ids[0]
return workcenter_id
@api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
if self._context.get('production_id'):
technology_design = self.env['sf.technology.design'].search(
[('production_id', '=', self._context.get('production_id'))])
route_ids = [t.route_id.id for t in technology_design]
domain = [('id', 'not in', route_ids)]
return self._search(domain, limit=limit, access_rights_uid=name_get_uid)
return super()._name_search(name, args, operator, limit, name_get_uid)

View File

@@ -6,22 +6,23 @@ class sf_technology_design(models.Model):
_name = 'sf.technology.design'
_description = "工艺设计"
name = fields.Char('工序')
route_id = fields.Many2one('mrp.routing.workcenter', '工序')
panel = fields.Char('加工面')
sequence = fields.Integer('序号')
time_cycle_manual = fields.Float('预计时长')
routing_tag = fields.Selection(related='route_id.routing_tag', string='标签', store=True)
time_cycle_manual = fields.Float(related='route_id.time_cycle_manual', string='预计时长')
production_id = fields.Many2one('mrp.production')
is_auto = fields.Boolean('是否自动生成', default=False)
active = fields.Boolean('有效', default=True)
def json_technology_design_str(self, k, route_name, time_cycle_manual, i):
def json_technology_design_str(self, k, route, i):
workorders_values_str = [0, '', {
'name': route_name,
'route_id': route.id,
'panel': k,
'sequence': i,
'is_auto': True,
'time_cycle_manual': time_cycle_manual}]
'is_auto': True}]
return workorders_values_str
def unlink_technology_design(self):
self.active = False

View File

@@ -367,10 +367,7 @@ class StockRule(models.Model):
for route in product_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(k,
route.route_workcenter_id.name,
route.route_workcenter_id.time_cycle_manual,
i))
self.env['sf.technology.design'].json_technology_design_str(k, route, i))
surface_technics_arr = []
route_workcenter_arr = []
for process_param in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids.filtered(
@@ -403,8 +400,7 @@ class StockRule(models.Model):
('id', 'in', route_workcenter_arr)])
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(k,
process_parameter.display_name,
route_production_process.time_cycle_manual,
route_production_process,
i))
productions.technology_design_ids = technology_design_values
@@ -624,12 +620,12 @@ class StockPicking(models.Model):
item.telephone_of_delivery = sale_id.telephone_of_delivery
item.address_of_delivery = sale_id.address_of_delivery
bom = self.env['mrp.bom'].sudo().search([('bom_line_ids.product_id', '=', self.move_ids.product_id.id)])
if bom:
if item.picking_type_id.sequence_code == 'DL':
item.retrospect_ref = bom.product_tmpl_id.default_code
elif item.picking_type_id.sequence_code in ['INT', 'PC']:
item.retrospect_ref = bom.product_tmpl_id.name
# bom = self.env['mrp.bom'].sudo().search([('bom_line_ids.product_id', '=', self.move_ids.product_id.id)])
# if bom:
# if item.picking_type_id.sequence_code == 'DL':
# item.retrospect_ref = bom.product_tmpl_id.default_code
# elif item.picking_type_id.sequence_code in ['INT', 'PC']:
# item.retrospect_ref = bom.product_tmpl_id.name
# 设置外协出入单的名称
def _get_name_Res(self, rescode):

View File

@@ -114,12 +114,18 @@
string="验证" type="object" class="oe_highlight"
confirm="There are no components to consume. Are you still sure you want to continue?"
data-hotkey="g" groups="sf_base.group_sf_mrp_user"/>
<button name="technology_confirm" string="工艺确认" type="object" class="oe_highlight"
attrs="{'invisible': ['|', '|', ('state', 'in', ('draft', 'cancel', 'done', 'to_close')), ('qty_producing', '=', 0), ('move_raw_ids', '!=', [])]}"></button>
</xpath>
<xpath expr="(//header//button[@name='button_mark_done'])[2]" position="replace">
<button name="button_mark_done"
attrs="{'invisible': ['|', '|', ('state', 'in', ('draft', 'cancel', 'done', 'to_close')), ('qty_producing', '=', 0), ('move_raw_ids', '=', [])]}"
string="验证" type="object" data-hotkey="g"
groups="sf_base.group_sf_mrp_user"/>
<button name="technology_confirm" string="工艺确认" type="object" class="oe_highlight"
attrs="{'invisible': ['|', '|', ('state', 'in', ('draft', 'cancel', 'done', 'to_close')), ('qty_producing', '=', 0), ('move_raw_ids', '=', [])]}"
></button>
</xpath>
<xpath expr="(//header//button[@name='button_scrap'])" position="replace">
<button name="button_scrap" invisible="1"/>
@@ -341,10 +347,15 @@
<field name="technology_design_ids" widget="one2many">
<tree editable="bottom">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="panel"/>
<field name="time_cycle_manual"/>
<field name="route_id" context="{'production_id': production_id}"
attrs="{'readonly': [('is_auto', '=', True)]}" options="{'no_create': True}"/>
<field name="panel" readonly="1"/>
<field name="routing_tag" readonly="1" widget="badge"
decoration-success="routing_tag == 'standard'"
decoration-warning="routing_tag == 'special'"/>
<field name="time_cycle_manual" attrs="{'readonly': [('is_auto', '=', True)]}"/>
<field name="is_auto" invisible="1"/>
<field name="production_id" invisible="1"/>
<button name="unlink_technology_design" confirm="是否确认删除?" class="oe_highlight"
attrs="{'invisible': [('is_auto', '=', True)]}" type="object"
string="删除"></button>