修改表面工艺外协工单流程
This commit is contained in:
@@ -317,7 +317,7 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
result = {
|
result = {
|
||||||
"type": "ir.actions.act_window",
|
"type": "ir.actions.act_window",
|
||||||
"res_model": "purchase.order",
|
"res_model": "purchase.order",
|
||||||
"res_id": purchase_orders_id,
|
"res_id": purchase_orders_id.id,
|
||||||
# "domain": [['id', 'in', self.purchase_id]],
|
# "domain": [['id', 'in', self.purchase_id]],
|
||||||
"name": _("Purchase Orders"),
|
"name": _("Purchase Orders"),
|
||||||
'view_mode': 'form',
|
'view_mode': 'form',
|
||||||
@@ -332,7 +332,7 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
for line in po.order_line:
|
for line in po.order_line:
|
||||||
if line.product_id.server_product_process_parameters_id == self.surface_technics_parameters_id:
|
if line.product_id.server_product_process_parameters_id == self.surface_technics_parameters_id:
|
||||||
if line.product_qty == 1:
|
if line.product_qty == 1:
|
||||||
purchase_orders_id = line.order_id.id
|
purchase_orders_id = line.order_id
|
||||||
return purchase_orders_id
|
return purchase_orders_id
|
||||||
|
|
||||||
supplier_id = fields.Many2one('res.partner', string='外协供应商')
|
supplier_id = fields.Many2one('res.partner', string='外协供应商')
|
||||||
@@ -1139,8 +1139,7 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
# workorder.state = 'waiting'
|
# workorder.state = 'waiting'
|
||||||
purchase_orders_id = self._get_surface_technics_purchase_ids()
|
purchase_orders_id = self._get_surface_technics_purchase_ids()
|
||||||
if purchase_orders_id:
|
if purchase_orders_id:
|
||||||
purchase_order = self.env['purchase.order'].browse(purchase_orders_id)
|
workorder.state = 'ready' if purchase_orders_id.state == 'purchase' else 'waiting'
|
||||||
workorder.state = 'ready' if purchase_order.state == 'purchase' else 'waiting'
|
|
||||||
else:
|
else:
|
||||||
workorder.state = 'waiting'
|
workorder.state = 'waiting'
|
||||||
|
|
||||||
@@ -1205,6 +1204,10 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
|
|
||||||
# 重写工单开始按钮方法
|
# 重写工单开始按钮方法
|
||||||
def button_start(self):
|
def button_start(self):
|
||||||
|
# 判断工单状态是否为等待组件
|
||||||
|
if self.state in ['waiting', 'pending']:
|
||||||
|
raise UserError('制造订单【%s】缺少组件信息!' % self.production_id.name)
|
||||||
|
|
||||||
if self.routing_type == 'CNC加工':
|
if self.routing_type == 'CNC加工':
|
||||||
self.env['sf.production.plan'].sudo().search([('name', '=', self.production_id.name)]).write({
|
self.env['sf.production.plan'].sudo().search([('name', '=', self.production_id.name)]).write({
|
||||||
'state': 'processing',
|
'state': 'processing',
|
||||||
@@ -1212,9 +1215,6 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
})
|
})
|
||||||
|
|
||||||
if self.sequence == 1:
|
if self.sequence == 1:
|
||||||
# 判断工单状态是否为等待组件
|
|
||||||
if self.state == 'waiting':
|
|
||||||
raise UserError('制造订单【%s】缺少组件信息!' % self.production_id.name)
|
|
||||||
# 判断是否有坯料的序列号信息
|
# 判断是否有坯料的序列号信息
|
||||||
boolean = False
|
boolean = False
|
||||||
if self.production_id.move_raw_ids:
|
if self.production_id.move_raw_ids:
|
||||||
@@ -1259,27 +1259,25 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
# [('barcode', 'ilike', 'VL-SPOC')]).id),
|
# [('barcode', 'ilike', 'VL-SPOC')]).id),
|
||||||
# ('origin', '=', self.production_id.name), ('state', 'not in', ['cancel', 'done'])])
|
# ('origin', '=', self.production_id.name), ('state', 'not in', ['cancel', 'done'])])
|
||||||
for mo in move_out:
|
for mo in move_out:
|
||||||
pick = self.env['stock.picking'].search([('id', '=', mo.picking_id.id), ('name', 'ilike', 'OCOUT'),
|
if mo.state != 'done':
|
||||||
('partner_id', '=', self.supplier_id.id)])
|
mo.write({'state': 'assigned', 'production_id': False})
|
||||||
if pick:
|
if not mo.move_line_ids:
|
||||||
if mo.state != 'done':
|
|
||||||
mo.write({'state': 'assigned', 'production_id': False})
|
|
||||||
self.env['stock.move.line'].create(mo.get_move_line(self.production_id, self))
|
self.env['stock.move.line'].create(mo.get_move_line(self.production_id, self))
|
||||||
product_qty = mo.product_uom._compute_quantity(
|
# product_qty = mo.product_uom._compute_quantity(
|
||||||
mo.product_uom_qty, mo.product_id.uom_id, rounding_method='HALF-UP')
|
# mo.product_uom_qty, mo.product_id.uom_id, rounding_method='HALF-UP')
|
||||||
available_quantity = self.env['stock.quant']._get_available_quantity(
|
# available_quantity = self.env['stock.quant']._get_available_quantity(
|
||||||
mo.product_id,
|
# mo.product_id,
|
||||||
mo.location_id,
|
# mo.location_id,
|
||||||
lot_id=mo.move_line_ids.lot_id,
|
# lot_id=mo.move_line_ids.lot_id,
|
||||||
strict=False,
|
# strict=False,
|
||||||
)
|
# )
|
||||||
mo._update_reserved_quantity(
|
# mo._update_reserved_quantity(
|
||||||
product_qty,
|
# product_qty,
|
||||||
available_quantity,
|
# available_quantity,
|
||||||
mo.location_id,
|
# mo.location_id,
|
||||||
lot_id=mo.move_line_ids.lot_id,
|
# lot_id=mo.move_line_ids.lot_id,
|
||||||
strict=False,
|
# strict=False,
|
||||||
)
|
# )
|
||||||
|
|
||||||
# move_out._action_assign()
|
# move_out._action_assign()
|
||||||
if self.state == 'waiting' or self.state == 'ready' or self.state == 'progress':
|
if self.state == 'waiting' or self.state == 'ready' or self.state == 'progress':
|
||||||
@@ -1384,6 +1382,13 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
picks = record.picking_ids.filtered(lambda p: p.state not in ('done'))
|
picks = record.picking_ids.filtered(lambda p: p.state not in ('done'))
|
||||||
if picks:
|
if picks:
|
||||||
raise UserError('请先完成该工单的工艺外协再进行操作')
|
raise UserError('请先完成该工单的工艺外协再进行操作')
|
||||||
|
# 表面工艺外协,最后一张工单
|
||||||
|
workorders = self.production_id.workorder_ids
|
||||||
|
subcontract_workorders = workorders.filtered(lambda wo: wo.is_subcontract == True).sorted('sequence')
|
||||||
|
if self == subcontract_workorders[-1]:
|
||||||
|
# 给下一个库存移动就绪
|
||||||
|
self.move_subcontract_workorder_ids[0].move_dest_ids._action_done()
|
||||||
|
# self.production_id.button_mark_done()
|
||||||
tem_date_planned_finished = record.date_planned_finished
|
tem_date_planned_finished = record.date_planned_finished
|
||||||
tem_date_finished = record.date_finished
|
tem_date_finished = record.date_finished
|
||||||
logging.info('routing_type:%s' % record.routing_type)
|
logging.info('routing_type:%s' % record.routing_type)
|
||||||
|
|||||||
@@ -634,27 +634,23 @@ class StockPicking(models.Model):
|
|||||||
num = "%04d" % m
|
num = "%04d" % m
|
||||||
return '%s%s' % (rescode, num)
|
return '%s%s' % (rescode, num)
|
||||||
|
|
||||||
# def button_validate(self):
|
def button_validate(self):
|
||||||
# res = super().button_validate()
|
res = super().button_validate()
|
||||||
# if res is True and self.picking_type_id.sequence_code == 'OCOUT':
|
picking_type_in = self.env.ref('sf_manufacturing.outcontract_picking_in').id
|
||||||
# # if self.id == move_out.picking_id.id:
|
if res is True and self.picking_type_id.id == picking_type_in:
|
||||||
# # if move_out.move_line_ids.workorder_id.state == 'progress':
|
# 如果是最后一张外协入库单,则设置库存位置的预留数量
|
||||||
# move_in = self.env['stock.move'].search(
|
move_in = self.move_ids
|
||||||
# [('location_dest_id', '=', self.env['stock.location'].search(
|
if move_in:
|
||||||
# [('barcode', 'ilike', 'WH-PREPRODUCTION')]).id),
|
workorder = move_in.subcontract_workorder_id
|
||||||
# ('location_id', '=', self.env['stock.location'].search(
|
workorders = workorder.production_id.workorder_ids
|
||||||
# [('barcode', 'ilike', 'VL-SPOC')]).id),
|
subcontract_workorders = workorders.filtered(lambda wo: wo.is_subcontract == True).sorted('sequence')
|
||||||
# ('origin', '=', self.origin), ('state', 'not in', ['cancel', 'done'])])
|
if workorder == subcontract_workorders[-1]:
|
||||||
# production = self.env['mrp.production'].search([('name', '=', self.origin)])
|
self.env['stock.quant']._update_reserved_quantity(
|
||||||
# for mi in move_in:
|
move_in.product_id, move_in.location_dest_id, move_in.product_uom_qty, lot_id=move_in.move_line_ids.lot_id,
|
||||||
# pick = self.env['stock.picking'].search([('id', '=', mi.picking_id.id), ('name', 'ilike', 'OCIN'),
|
package_id=False, owner_id=False, strict=False
|
||||||
# ('partner_id', '=', self.partner_id.id)])
|
)
|
||||||
# if pick:
|
|
||||||
# if mi.state != 'done':
|
return res
|
||||||
# mi.write({'state': 'assigned'})
|
|
||||||
# self.env['stock.move.line'].create(mi.get_move_line(production, None))
|
|
||||||
|
|
||||||
# return res
|
|
||||||
|
|
||||||
# 创建 外协出库入单
|
# 创建 外协出库入单
|
||||||
def create_outcontract_picking(self, workorders, item, sorted_workorders):
|
def create_outcontract_picking(self, workorders, item, sorted_workorders):
|
||||||
@@ -677,13 +673,12 @@ class StockPicking(models.Model):
|
|||||||
'partner_id': self.partner_id.id,
|
'partner_id': self.partner_id.id,
|
||||||
})
|
})
|
||||||
move_dest_id = False
|
move_dest_id = False
|
||||||
# 如果当前工单是制造订单的最后一个工单
|
# 如果当前工单是是制造订单的最后一个工单
|
||||||
# if workorder == item.workorder_ids[-1]:
|
if workorder == item.workorder_ids[-1]:
|
||||||
# # 找到制造订单对应的move
|
move_dest_id = item.move_raw_ids[0].id
|
||||||
# move_dest_id = item.move_raw_ids[0].move_orig_ids[0].id
|
else:
|
||||||
# else:
|
# 从sorted_workorders中找到上一工单的move
|
||||||
# # 从sorted_workorders中找到上一工单的move
|
move_dest_id = sorted_workorders[sorted_workorders.index(workorder) - 1].move_subcontract_workorder_ids[1].id
|
||||||
# move_dest_id = sorted_workorders[sorted_workorders.index(workorder) - 1].move_subcontract_workorder_ids[1].id
|
|
||||||
new_picking = True
|
new_picking = True
|
||||||
outcontract_picking_type_in = self.env.ref(
|
outcontract_picking_type_in = self.env.ref(
|
||||||
'sf_manufacturing.outcontract_picking_in').id,
|
'sf_manufacturing.outcontract_picking_in').id,
|
||||||
@@ -706,7 +701,20 @@ class StockPicking(models.Model):
|
|||||||
moves_out.write(
|
moves_out.write(
|
||||||
{'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)
|
||||||
|
return moves_in, moves_out
|
||||||
|
|
||||||
|
@api.depends('move_type', 'immediate_transfer', 'move_ids.state', 'move_ids.picking_id')
|
||||||
|
def _compute_state(self):
|
||||||
|
super(StockPicking, self)._compute_state()
|
||||||
|
for picking in self:
|
||||||
|
# 外协出库单根据工单状态,采购单状态来确定
|
||||||
|
picking_type_id = self.env.ref('sf_manufacturing.outcontract_picking_out').id
|
||||||
|
if picking.picking_type_id.id == picking_type_id:
|
||||||
|
if picking.move_ids:
|
||||||
|
workorder = picking.move_ids[0].subcontract_workorder_id
|
||||||
|
if picking.state == 'assigned':
|
||||||
|
if workorder.state in ['pending', 'waiting'] or workorder._get_surface_technics_purchase_ids().state in ['draft', 'sent']:
|
||||||
|
picking.state = 'waiting'
|
||||||
|
|
||||||
|
|
||||||
class ReStockMove(models.Model):
|
class ReStockMove(models.Model):
|
||||||
@@ -753,7 +761,7 @@ class ReStockMove(models.Model):
|
|||||||
'picking_type_id': picking_type_id,
|
'picking_type_id': picking_type_id,
|
||||||
'location_id': self.mapped('location_id').id,
|
'location_id': self.mapped('location_id').id,
|
||||||
'location_dest_id': self.mapped('location_dest_id').id,
|
'location_dest_id': self.mapped('location_dest_id').id,
|
||||||
'state': 'confirmed',
|
'state': 'waiting',
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_move_line(self, production_id, sorted_workorders):
|
def get_move_line(self, production_id, sorted_workorders):
|
||||||
|
|||||||
Reference in New Issue
Block a user