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