修改表面工艺外协工单流程

This commit is contained in:
胡尧
2024-12-05 01:33:46 +08:00
parent ef60f36c90
commit 5f12976d8f
2 changed files with 69 additions and 56 deletions

View File

@@ -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)