Merge branch 'develop' of https://e.coding.net/jikimo-hn/jikimo_sfs/jikimo_sf into feature/制造功能优化

This commit is contained in:
mgw
2024-12-30 08:57:49 +08:00
3 changed files with 52 additions and 42 deletions

View File

@@ -790,6 +790,7 @@ class MrpProduction(models.Model):
groupby(production_all, key=lambda x: x.product_id.id)} groupby(production_all, key=lambda x: x.product_id.id)}
for product_id, pd in grouped_product_ids.items(): for product_id, pd in grouped_product_ids.items():
product_id_to_production_names[product_id] = [p.name for p in pd] product_id_to_production_names[product_id] = [p.name for p in pd]
sorted_workorders = None
for production in production_all: for production in production_all:
proc_workorders = [] proc_workorders = []
process_parameter_workorder = self.env['mrp.workorder'].search( process_parameter_workorder = self.env['mrp.workorder'].search(
@@ -841,6 +842,8 @@ class MrpProduction(models.Model):
# self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production) # self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production)
# self.env['purchase.order'].get_purchase_order(consecutive_workorders, production, # self.env['purchase.order'].get_purchase_order(consecutive_workorders, production,
# product_id_to_production_names) # product_id_to_production_names)
if not sorted_workorders:
return
for workorders in reversed(sorted_workorders): for workorders in reversed(sorted_workorders):
self.env['stock.picking'].create_outcontract_picking(workorders, production, sorted_workorders) self.env['stock.picking'].create_outcontract_picking(workorders, production, sorted_workorders)
self.env['purchase.order'].get_purchase_order(workorders, production, product_id_to_production_names) self.env['purchase.order'].get_purchase_order(workorders, production, product_id_to_production_names)

View File

@@ -657,15 +657,19 @@ class StockPicking(models.Model):
if move_out: if move_out:
workorder = move_out.subcontract_workorder_id workorder = move_out.subcontract_workorder_id
workorder.button_start() workorder.button_start()
if self.location_id.name == '成品存货区' and self.location_dest_id.name == '客户':
sale_id = self.env['sale.order'].sudo().search(
[('name', '=', self.origin)])
if sale_id and all(move.product_uom_qty == move.quantity_done for move in self.move_ids):
sale_id.write({'state':'delivered'})
return res return res
# 创建 外协出库入单 # 创建 外协出库入单
def create_outcontract_picking(self, workorders, item, sorted_workorders): def create_outcontract_picking(self, workorders, item, sorted_workorders):
for workorder in workorders: for workorder in workorders:
if workorder.move_subcontract_workorder_ids: if workorder.move_subcontract_workorder_ids:
workorder.move_subcontract_workorder_ids.write({'state': 'waiting'}) workorder.move_subcontract_workorder_ids.write({'state': 'cancel'})
workorder.move_subcontract_workorder_ids.picking_id.write({'state': 'waiting'}) workorder.move_subcontract_workorder_ids.picking_id.write({'state': 'cancel'})
else:
# 创建一个新的补货组 # 创建一个新的补货组
procurement_group_id = self.env['procurement.group'].create({ procurement_group_id = self.env['procurement.group'].create({
'name': workorder.name, 'name': workorder.name,
@@ -673,7 +677,7 @@ class StockPicking(models.Model):
}) })
move_dest_id = False move_dest_id = False
# 如果当前工单是是制造订单的最后一个工艺外协工单 # 如果当前工单是是制造订单的最后一个工艺外协工单
if workorder == next((workorder for workorder in reversed(item.workorder_ids) if workorder.is_subcontract), None): if workorder == next((workorder for workorder in reversed(sorted_workorders) if workorder.is_subcontract), None):
move_dest_id = item.move_raw_ids[0].id move_dest_id = item.move_raw_ids[0].id
else: else:
# 从sorted_workorders中找到上一工单的move # 从sorted_workorders中找到上一工单的move
@@ -704,6 +708,9 @@ class StockPicking(models.Model):
{'picking_id': picking_out.id, 'state': 'waiting'}) {'picking_id': picking_out.id, 'state': 'waiting'})
moves_out._assign_picking_post_process(new=new_picking) moves_out._assign_picking_post_process(new=new_picking)
@api.depends('move_type', 'immediate_transfer', 'move_ids.state', 'move_ids.picking_id') @api.depends('move_type', 'immediate_transfer', 'move_ids.state', 'move_ids.picking_id')
def _compute_state(self): def _compute_state(self):
super(StockPicking, self)._compute_state() super(StockPicking, self)._compute_state()

View File

@@ -126,16 +126,16 @@ class StockLot(models.Model):
tool_material_search_id = fields.Many2one('sf.tool.material.search', string='刀具物料搜索') tool_material_search_id = fields.Many2one('sf.tool.material.search', string='刀具物料搜索')
fixture_material_search_id = fields.Many2one('sf.fixture.material.search', string='夹具物料搜索') fixture_material_search_id = fields.Many2one('sf.fixture.material.search', string='夹具物料搜索')
tool_material_status = fields.Selection( tool_material_status = fields.Selection(
[('未入库', '未入库'), ('可用', '可用'), ('在用', '空闲'), ('报废', '报废')], string='状态', [('未入库', '未入库'), ('可用', '空闲'), ('在用', '占用'), ('报废', '报废')], string='状态',
compute='_compute_tool_material_status', store=True) compute='_compute_tool_material_status', store=True)
@api.depends('quant_ids') @api.depends('quant_ids')
def _compute_tool_material_status(self): def _compute_tool_material_status(self):
for record in self: for record in self:
if record: if record:
if record.product_id.categ_id.name in ['刀具', '夹具']: if record.product_id.categ_id.name in ['刀具']:
if record.quant_ids: if record.quant_ids:
if record.quant_ids[-1].location_id.name in ['刀具房', '夹具房']: if record.quant_ids[-1].location_id.name in ['刀具房']:
record.tool_material_status = '可用' record.tool_material_status = '可用'
elif record.quant_ids[-1].location_id.name == '刀具组装位置': elif record.quant_ids[-1].location_id.name == '刀具组装位置':
record.tool_material_status = '在用' record.tool_material_status = '在用'