工艺外协代码
This commit is contained in:
@@ -85,6 +85,7 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
item.pr_mp_count = len(pr_ids)
|
item.pr_mp_count = len(pr_ids)
|
||||||
else:
|
else:
|
||||||
item.pr_mp_count = 0
|
item.pr_mp_count = 0
|
||||||
|
|
||||||
@api.depends('state')
|
@api.depends('state')
|
||||||
def _compute_back_button_display(self):
|
def _compute_back_button_display(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
@@ -484,6 +485,7 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
'view_mode': 'tree,form',
|
'view_mode': 'tree,form',
|
||||||
})
|
})
|
||||||
return action
|
return action
|
||||||
|
|
||||||
def action_view_surface_technics_purchase(self):
|
def action_view_surface_technics_purchase(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
# if self.routing_type == '表面工艺':
|
# if self.routing_type == '表面工艺':
|
||||||
@@ -512,7 +514,8 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def _get_surface_technics_purchase_ids(self):
|
def _get_surface_technics_purchase_ids(self):
|
||||||
domain = [('origin', 'like', '%' + self.production_id.name + '%'), ('purchase_type', '=', 'consignment'), ('state', '!=', 'cancel')]
|
domain = [('origin', 'like', '%' + self.production_id.name + '%'), ('purchase_type', '=', 'consignment'),
|
||||||
|
('state', '!=', 'cancel')]
|
||||||
# domain = [('origin', 'like', '%' + self.production_id.name + '%'), ('purchase_type', '=', 'consignment')]
|
# domain = [('origin', 'like', '%' + self.production_id.name + '%'), ('purchase_type', '=', 'consignment')]
|
||||||
# domain = [('group_id', '=', self.production_id.procurement_group_id.id), ('purchase_type', '=', 'consignment')]
|
# domain = [('group_id', '=', self.production_id.procurement_group_id.id), ('purchase_type', '=', 'consignment')]
|
||||||
purchase_orders = self.env['purchase.order'].search(domain, order='id desc')
|
purchase_orders = self.env['purchase.order'].search(domain, order='id desc')
|
||||||
@@ -1248,6 +1251,7 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
lambda line: line.lot_id.id == lot_id
|
lambda line: line.lot_id.id == lot_id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def _process_compute_state(self):
|
def _process_compute_state(self):
|
||||||
sorted_workorders = sorted(self, key=lambda x: x.sequence)
|
sorted_workorders = sorted(self, key=lambda x: x.sequence)
|
||||||
for workorder in sorted_workorders:
|
for workorder in sorted_workorders:
|
||||||
@@ -1288,7 +1292,10 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
purchase_orders_id = self._get_surface_technics_purchase_ids()
|
purchase_orders_id = self._get_surface_technics_purchase_ids()
|
||||||
if purchase_orders_id.state == 'purchase':
|
if purchase_orders_id.state == 'purchase':
|
||||||
workorder.state = 'ready'
|
workorder.state = 'ready'
|
||||||
move_out = workorder.move_subcontract_workorder_ids[1]
|
picking_id = workorder.production_id.picking_ids.filtered(
|
||||||
|
lambda wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区')
|
||||||
|
move_out = picking_id.move_ids
|
||||||
|
# move_out = workorder.move_subcontract_workorder_ids[1]
|
||||||
for mo in move_out:
|
for mo in move_out:
|
||||||
if mo.state != 'done':
|
if mo.state != 'done':
|
||||||
mo.write({'state': 'assigned', 'production_id': False})
|
mo.write({'state': 'assigned', 'production_id': False})
|
||||||
@@ -1327,7 +1334,10 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
if purchase_orders_id:
|
if purchase_orders_id:
|
||||||
if purchase_orders_id.state == 'purchase':
|
if purchase_orders_id.state == 'purchase':
|
||||||
workorder.state = 'ready'
|
workorder.state = 'ready'
|
||||||
move_out = workorder.move_subcontract_workorder_ids[1]
|
picking_id = workorder.production_id.picking_ids.filtered(
|
||||||
|
lambda
|
||||||
|
wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区')
|
||||||
|
move_out = picking_id.move_ids
|
||||||
for mo in move_out:
|
for mo in move_out:
|
||||||
if mo.state != 'done':
|
if mo.state != 'done':
|
||||||
mo.write({'state': 'assigned', 'production_id': False})
|
mo.write({'state': 'assigned', 'production_id': False})
|
||||||
@@ -1337,7 +1347,6 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
else:
|
else:
|
||||||
workorder.state = 'waiting'
|
workorder.state = 'waiting'
|
||||||
|
|
||||||
|
|
||||||
@api.depends('production_availability', 'blocked_by_workorder_ids', 'blocked_by_workorder_ids.state',
|
@api.depends('production_availability', 'blocked_by_workorder_ids', 'blocked_by_workorder_ids.state',
|
||||||
'production_id.tool_state', 'production_id.schedule_state', 'sequence',
|
'production_id.tool_state', 'production_id.schedule_state', 'sequence',
|
||||||
'production_id.programming_state')
|
'production_id.programming_state')
|
||||||
@@ -1369,7 +1378,8 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
# 判断是否有坯料的序列号信息
|
# 判断是否有坯料的序列号信息
|
||||||
boolean = False
|
boolean = False
|
||||||
if self.production_id.move_raw_ids:
|
if self.production_id.move_raw_ids:
|
||||||
if self.production_id.move_raw_ids[0].product_id.categ_type == '坯料' and self.production_id.move_raw_ids[0].product_id.tracking == 'serial':
|
if self.production_id.move_raw_ids[0].product_id.categ_type == '坯料' and \
|
||||||
|
self.production_id.move_raw_ids[0].product_id.tracking == 'serial':
|
||||||
if self.production_id.move_raw_ids[0].move_line_ids:
|
if self.production_id.move_raw_ids[0].move_line_ids:
|
||||||
if self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name:
|
if self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name:
|
||||||
boolean = True
|
boolean = True
|
||||||
@@ -1401,7 +1411,10 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
# 表面工艺外协出库单
|
# 表面工艺外协出库单
|
||||||
if self.routing_type == '表面工艺':
|
if self.routing_type == '表面工艺':
|
||||||
if self.is_subcontract is True:
|
if self.is_subcontract is True:
|
||||||
move_out = self.move_subcontract_workorder_ids[1]
|
picking_id = self.production_id.picking_ids.filtered(
|
||||||
|
lambda wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区')
|
||||||
|
move_out = picking_id.move_ids
|
||||||
|
# move_out = self.move_subcontract_workorder_ids[1]
|
||||||
# move_out = self.env['stock.move'].search(
|
# move_out = self.env['stock.move'].search(
|
||||||
# [('location_id', '=', self.env['stock.location'].search(
|
# [('location_id', '=', self.env['stock.location'].search(
|
||||||
# [('barcode', 'ilike', 'WH-PREPRODUCTION')]).id),
|
# [('barcode', 'ilike', 'WH-PREPRODUCTION')]).id),
|
||||||
@@ -1820,7 +1833,7 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
orderby=orderby,
|
orderby=orderby,
|
||||||
lazy=lazy
|
lazy=lazy
|
||||||
)
|
)
|
||||||
|
|
||||||
model_id = fields.Char('模型ID', related='production_id.model_id')
|
model_id = fields.Char('模型ID', related='production_id.model_id')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -631,28 +631,62 @@ class StockPicking(models.Model):
|
|||||||
move.action_clear_lines_show_details()
|
move.action_clear_lines_show_details()
|
||||||
move.action_show_details()
|
move.action_show_details()
|
||||||
res = super().button_validate()
|
res = super().button_validate()
|
||||||
picking_type_in = self.env.ref('sf_manufacturing.outcontract_picking_in').id
|
lot_ids = None
|
||||||
if res is True and self.picking_type_id.id == picking_type_in:
|
product_ids = self.move_ids.mapped('product_id')
|
||||||
|
if not self.move_ids[0].product_id.single_manufacturing and self.move_ids[0].product_id.tracking == 'none':
|
||||||
|
lot_ids = self.move_ids.move_line_ids.mapped('lot_id')
|
||||||
|
production_ids = self.sale_order_id.mrp_production_ids if self.sale_order_id else self.env['mrp.production']
|
||||||
|
if res and self.location_id.name == '外协收料区' and self.location_dest_id.name == '制造前':
|
||||||
# 如果是最后一张外协入库单,则设置库存位置的预留数量
|
# 如果是最后一张外协入库单,则设置库存位置的预留数量
|
||||||
move_in = self.move_ids
|
for production_id in production_ids:
|
||||||
if move_in:
|
if lot_ids:
|
||||||
workorder = move_in.subcontract_workorder_id
|
lot_id = production_id.move_raw_ids.move_line_ids.lot_id
|
||||||
workorders = workorder.production_id.workorder_ids
|
# picking_ids = production_id.picking_ids.filtered(
|
||||||
subcontract_workorders = workorders.filtered(
|
# lambda wk: wk.location_id.name == '外协收料区' and wk.location_dest_id.name == '制造前')
|
||||||
lambda wo: wo.is_subcontract == True and wo.state != 'cancel').sorted('sequence')
|
if lot_id in lot_ids:
|
||||||
# if workorder == subcontract_workorders[-1]:
|
workorder_id = production_id.workorder_ids.filtered(
|
||||||
# self.env['stock.quant']._update_reserved_quantity(
|
lambda a: a.state == 'progress' and a.is_subcontract)
|
||||||
# move_in.product_id, move_in.location_dest_id, move_in.product_uom_qty,
|
if not workorder_id:
|
||||||
# lot_id=move_in.move_line_ids.lot_id,
|
continue
|
||||||
# package_id=False, owner_id=False, strict=False
|
workorder_id.button_finish()
|
||||||
# )
|
else:
|
||||||
workorder.button_finish()
|
workorder_id = production_id.workorder_ids.filtered(lambda a: a.state == 'progress' and a.is_subcontract)
|
||||||
picking_type_out = self.env.ref('sf_manufacturing.outcontract_picking_out').id
|
if not workorder_id:
|
||||||
if res and self.picking_type_id.id == picking_type_out:
|
continue
|
||||||
move_out = self.move_ids
|
workorder_id.button_finish()
|
||||||
if move_out:
|
# lot_id = workorder.production_id.move_raw_ids.move_line_ids.lot_id
|
||||||
workorder = move_out.subcontract_workorder_id
|
# picking_ids = workorder.production_id.picking_ids.filtered(
|
||||||
workorder.button_start()
|
# lambda wk: wk.location_id.name == '外协收料区' and wk.location_dest_id.name == '制造前')
|
||||||
|
|
||||||
|
# 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 and wo.state != 'cancel').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
|
||||||
|
# # )
|
||||||
|
# workorder.button_finish()
|
||||||
|
if res and self.location_id.name == '制造前' and self.location_dest_id.name == '外协加工区':
|
||||||
|
for production_id in production_ids:
|
||||||
|
if lot_ids:
|
||||||
|
lot_id = production_id.move_raw_ids.move_line_ids.lot_id
|
||||||
|
# picking_ids = production_id.picking_ids.filtered(
|
||||||
|
# lambda wk: wk.location_id.name == '外协收料区' and wk.location_dest_id.name == '制造前')
|
||||||
|
if lot_id in lot_ids:
|
||||||
|
workorder_id = production_id.workorder_ids.filtered(
|
||||||
|
lambda a: a.state == 'progress' and a.is_subcontract)
|
||||||
|
if not workorder_id:
|
||||||
|
continue
|
||||||
|
workorder_id.button_finish()
|
||||||
|
else:
|
||||||
|
workorder_id = production_id.workorder_ids.filtered(lambda a: a.state == 'ready' and a.is_subcontract)
|
||||||
|
if not workorder_id:
|
||||||
|
continue
|
||||||
|
workorder_id.button_start()
|
||||||
if self.location_id.name == '成品存货区' and self.location_dest_id.name == '客户':
|
if self.location_id.name == '成品存货区' and self.location_dest_id.name == '客户':
|
||||||
sale_id = self.env['sale.order'].sudo().search(
|
sale_id = self.env['sale.order'].sudo().search(
|
||||||
[('name', '=', self.origin)])
|
[('name', '=', self.origin)])
|
||||||
|
|||||||
Reference in New Issue
Block a user