修改工艺外协工单
This commit is contained in:
@@ -634,71 +634,74 @@ 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))
|
||||
# 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
|
||||
# return res
|
||||
|
||||
# 创建 外协出库入单
|
||||
def create_outcontract_picking(self, sorted_workorders_arr, item):
|
||||
def create_outcontract_picking(self, workorders, item, sorted_workorders):
|
||||
domain = [('origin', '=', item.name), ('name', 'ilike', 'OCOUT')]
|
||||
if len(sorted_workorders_arr) > 1:
|
||||
sorted_workorders_arr = sorted_workorders_arr[0]
|
||||
if len(workorders) > 1:
|
||||
workorders = workorders[0]
|
||||
else:
|
||||
domain += [
|
||||
('surface_technics_parameters_id', '=', sorted_workorders_arr[0].surface_technics_parameters_id.id)]
|
||||
('surface_technics_parameters_id', '=', workorders[0].surface_technics_parameters_id.id)]
|
||||
stock_picking = self.env['stock.picking'].search(domain)
|
||||
if not stock_picking:
|
||||
for sorted_workorders in sorted_workorders_arr:
|
||||
for workorder in workorders:
|
||||
# pick_ids = []
|
||||
if not sorted_workorders.picking_ids:
|
||||
if not workorder.picking_ids:
|
||||
# outcontract_stock_move = self.env['stock.move'].search([('production_id', '=', item.id)])
|
||||
# if not outcontract_stock_move:
|
||||
# 创建一个新的补货组
|
||||
procurement_group_id = self.env['procurement.group'].create({
|
||||
'name': sorted_workorders.name,
|
||||
'name': workorder.name,
|
||||
'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
|
||||
new_picking = True
|
||||
location_id = self.env['stock.location'].search(
|
||||
[('barcode', 'ilike', 'VL-SPOC')]).id,
|
||||
location_dest_id = self.env['stock.location'].search(
|
||||
[('barcode', 'ilike', 'WH-PREPRODUCTION')]).id,
|
||||
outcontract_picking_type_in = self.env.ref(
|
||||
'sf_manufacturing.outcontract_picking_in').id,
|
||||
outcontract_picking_type_out = self.env.ref(
|
||||
'sf_manufacturing.outcontract_picking_out').id,
|
||||
moves_in = self.env['stock.move'].sudo().create(
|
||||
self.env['stock.move']._get_stock_move_values_Res(item, location_id, location_dest_id,
|
||||
outcontract_picking_type_in, procurement_group_id.id))
|
||||
self.env['stock.move']._get_stock_move_values_Res(item, outcontract_picking_type_in, procurement_group_id.id, move_dest_id))
|
||||
picking_in = self.create(
|
||||
moves_in._get_new_picking_values_Res(item, sorted_workorders, 'WH/OCIN/'))
|
||||
moves_in._get_new_picking_values_Res(item, workorder, 'WH/OCIN/'))
|
||||
# pick_ids.append(picking_in.id)
|
||||
moves_in.write(
|
||||
{'picking_id': picking_in.id, 'state': 'waiting'})
|
||||
moves_in._assign_picking_post_process(new=new_picking)
|
||||
moves_out = self.env['stock.move'].sudo().create(
|
||||
self.env['stock.move']._get_stock_move_values_Res(item, location_dest_id, location_id,
|
||||
outcontract_picking_type_out, procurement_group_id.id, moves_in.id))
|
||||
self.env['stock.move']._get_stock_move_values_Res(item, outcontract_picking_type_out, procurement_group_id.id, moves_in.id))
|
||||
workorder.write({'move_subcontract_workorder_ids': [(6, 0, [moves_in.id, moves_out.id])]})
|
||||
picking_out = self.create(
|
||||
moves_out._get_new_picking_values_Res(item, sorted_workorders, 'WH/OCOUT/'))
|
||||
moves_out._get_new_picking_values_Res(item, workorder, 'WH/OCOUT/'))
|
||||
# pick_ids.append(picking_out.id)
|
||||
moves_out.write(
|
||||
{'picking_id': picking_out.id, 'state': 'waiting'})
|
||||
@@ -713,16 +716,17 @@ class ReStockMove(models.Model):
|
||||
materiel_width = fields.Float(string='物料宽度', digits=(16, 4))
|
||||
materiel_height = fields.Float(string='物料高度', digits=(16, 4))
|
||||
|
||||
def _get_stock_move_values_Res(self, item, location_src_id, location_dest_id, picking_type_id, group_id, move_dest_ids=False):
|
||||
route = self.env['stock.route'].sudo().search([('name', '=', '表面工艺外协')])
|
||||
def _get_stock_move_values_Res(self, item, picking_type_id, group_id, move_dest_ids=False):
|
||||
route_id = self.env.ref('sf_manufacturing.route_surface_technology_outsourcing').id
|
||||
stock_rule = self.env['stock.rule'].sudo().search([('route_id', '=', route_id), ('picking_type_id', '=', picking_type_id)])
|
||||
move_values = {
|
||||
'name': '推',
|
||||
'company_id': item.company_id.id,
|
||||
'product_id': item.bom_id.bom_line_ids.product_id.id,
|
||||
'product_uom': item.bom_id.bom_line_ids.product_uom_id.id,
|
||||
'product_uom_qty': 1.0,
|
||||
'location_id': location_src_id,
|
||||
'location_dest_id': location_dest_id,
|
||||
'location_id': stock_rule.location_src_id.id,
|
||||
'location_dest_id': stock_rule.location_dest_id.id,
|
||||
'origin': item.name,
|
||||
'group_id': group_id,
|
||||
'move_dest_ids': [(6, 0, [move_dest_ids])] if move_dest_ids else False,
|
||||
@@ -991,6 +995,8 @@ class ReStockMove(models.Model):
|
||||
res['origin'] = ','.join(productions.mapped('name'))
|
||||
res['retrospect_ref'] = production.product_id.name
|
||||
return res
|
||||
|
||||
subcontract_workorder_id = fields.Many2one('mrp.workorder', '外协工单组件', check_company=True, index='btree_not_null')
|
||||
|
||||
|
||||
class ReStockQuant(models.Model):
|
||||
|
||||
Reference in New Issue
Block a user