修改工艺外协工单
This commit is contained in:
@@ -313,14 +313,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
# if technology_design.is_auto is False:
|
||||
# domain = [('origin', '=', self.production_id.name)]
|
||||
# else:
|
||||
domain = [('origin', '=', self.production_id.name), ('purchase_type', '=', 'consignment')]
|
||||
purchase_orders = self.env['purchase.order'].search(domain)
|
||||
purchase_orders_id = None
|
||||
for po in purchase_orders:
|
||||
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 = self._get_surface_technics_purchase_ids()
|
||||
result = {
|
||||
"type": "ir.actions.act_window",
|
||||
"res_model": "purchase.order",
|
||||
@@ -330,6 +323,17 @@ class ResMrpWorkOrder(models.Model):
|
||||
'view_mode': 'form',
|
||||
}
|
||||
return result
|
||||
|
||||
def _get_surface_technics_purchase_ids(self):
|
||||
domain = [('origin', '=', self.production_id.name), ('purchase_type', '=', 'consignment')]
|
||||
purchase_orders = self.env['purchase.order'].search(domain)
|
||||
purchase_orders_id = None
|
||||
for po in purchase_orders:
|
||||
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
|
||||
return purchase_orders_id
|
||||
|
||||
supplier_id = fields.Many2one('res.partner', string='外协供应商')
|
||||
equipment_id = fields.Many2one('maintenance.equipment', string='加工设备', tracking=True)
|
||||
@@ -1027,47 +1031,47 @@ class ResMrpWorkOrder(models.Model):
|
||||
'production_id.programming_state')
|
||||
def _compute_state(self):
|
||||
# super()._compute_state()
|
||||
for workorder in self:
|
||||
if workorder.sequence != 1:
|
||||
previous_workorder = self.env['mrp.workorder'].search(
|
||||
[('production_id', '=', workorder.production_id.id),
|
||||
('sequence', '=', workorder.sequence - 1)])
|
||||
if workorder.state == 'pending':
|
||||
if all([wo.state in ('done', 'cancel') for wo in workorder.blocked_by_workorder_ids]):
|
||||
if workorder.production_id.reservation_state == 'assigned' and workorder.production_id.schedule_state == '已排':
|
||||
if ((workorder.sequence == 1 and not workorder.blocked_by_workorder_ids)
|
||||
or (workorder.blocked_by_workorder_ids.state in ('done', 'cancel')
|
||||
and workorder.blocked_by_workorder_ids.test_results not in ['报废', '返工'])
|
||||
or (previous_workorder.state in ('done', 'cancel')
|
||||
and not workorder.blocked_by_workorder_ids
|
||||
and previous_workorder.test_results not in ['报废', '返工'])
|
||||
):
|
||||
workorder.state = 'ready'
|
||||
continue
|
||||
if workorder.production_id.schedule_state == '未排' and workorder.state in ('waiting', 'ready'):
|
||||
if workorder.sequence != 1:
|
||||
workorder.state = 'pending'
|
||||
continue
|
||||
if workorder.state not in ('waiting', 'ready'):
|
||||
continue
|
||||
if workorder.state in (
|
||||
'waiting') and workorder.sequence == 1 and workorder.production_id.schedule_state == '已排':
|
||||
workorder.state = 'ready'
|
||||
continue
|
||||
if not all([wo.state in ('done', 'cancel') for wo in workorder.blocked_by_workorder_ids]):
|
||||
workorder.state = 'pending'
|
||||
if workorder.state in ['waiting']:
|
||||
if previous_workorder.state == 'waiting':
|
||||
workorder.state = 'pending'
|
||||
if workorder.sequence == 1 and workorder.state == 'pending':
|
||||
workorder.state = 'waiting'
|
||||
continue
|
||||
if workorder.production_id.reservation_state not in ('waiting', 'confirmed', 'assigned'):
|
||||
continue
|
||||
if workorder.production_id.reservation_state == 'assigned' and workorder.state == 'waiting' and workorder.production_id.schedule_state == '已排':
|
||||
workorder.state = 'ready'
|
||||
elif workorder.production_id.reservation_state != 'assigned' and workorder.state == 'ready':
|
||||
workorder.state = 'waiting'
|
||||
# for workorder in self:
|
||||
# if workorder.sequence != 1:
|
||||
# previous_workorder = self.env['mrp.workorder'].search(
|
||||
# [('production_id', '=', workorder.production_id.id),
|
||||
# ('sequence', '=', workorder.sequence - 1)])
|
||||
# if workorder.state == 'pending':
|
||||
# if all([wo.state in ('done', 'cancel') for wo in workorder.blocked_by_workorder_ids]):
|
||||
# if workorder.production_id.reservation_state == 'assigned' and workorder.production_id.schedule_state == '已排':
|
||||
# if ((workorder.sequence == 1 and not workorder.blocked_by_workorder_ids)
|
||||
# or (workorder.blocked_by_workorder_ids.state in ('done', 'cancel')
|
||||
# and workorder.blocked_by_workorder_ids.test_results not in ['报废', '返工'])
|
||||
# or (previous_workorder.state in ('done', 'cancel')
|
||||
# and not workorder.blocked_by_workorder_ids
|
||||
# and previous_workorder.test_results not in ['报废', '返工'])
|
||||
# ):
|
||||
# workorder.state = 'ready'
|
||||
# continue
|
||||
# if workorder.production_id.schedule_state == '未排' and workorder.state in ('waiting', 'ready'):
|
||||
# if workorder.sequence != 1:
|
||||
# workorder.state = 'pending'
|
||||
# continue
|
||||
# if workorder.state not in ('waiting', 'ready'):
|
||||
# continue
|
||||
# if workorder.state in (
|
||||
# 'waiting') and workorder.sequence == 1 and workorder.production_id.schedule_state == '已排':
|
||||
# workorder.state = 'ready'
|
||||
# continue
|
||||
# if not all([wo.state in ('done', 'cancel') for wo in workorder.blocked_by_workorder_ids]):
|
||||
# workorder.state = 'pending'
|
||||
# if workorder.state in ['waiting']:
|
||||
# if previous_workorder.state == 'waiting':
|
||||
# workorder.state = 'pending'
|
||||
# if workorder.sequence == 1 and workorder.state == 'pending':
|
||||
# workorder.state = 'waiting'
|
||||
# continue
|
||||
# if workorder.production_id.reservation_state not in ('waiting', 'confirmed', 'assigned'):
|
||||
# continue
|
||||
# if workorder.production_id.reservation_state == 'assigned' and workorder.state == 'waiting' and workorder.production_id.schedule_state == '已排':
|
||||
# workorder.state = 'ready'
|
||||
# elif workorder.production_id.reservation_state != 'assigned' and workorder.state == 'ready':
|
||||
# workorder.state = 'waiting'
|
||||
|
||||
for workorder in self:
|
||||
# 如果工单的工序没有进行排序则跳出循环
|
||||
@@ -1118,21 +1122,27 @@ class ResMrpWorkOrder(models.Model):
|
||||
if workorder.is_subcontract is False:
|
||||
workorder.state = 'ready'
|
||||
else:
|
||||
production_programming = self.env['mrp.production'].search(
|
||||
[('origin', '=', self.production_id.origin)], order='name asc')
|
||||
production_no_remanufacture = production_programming.filtered(
|
||||
lambda a: a.is_remanufacture is False)
|
||||
production_list = [production.name for production in production_programming]
|
||||
purchase_orders = self.env['purchase.order'].search(
|
||||
[('origin', 'ilike', ','.join(production_list))])
|
||||
for line in purchase_orders.order_line:
|
||||
if (
|
||||
line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id
|
||||
and line.product_qty == len(production_no_remanufacture)):
|
||||
if all(pur_order.state == 'purchase' for pur_order in purchase_orders):
|
||||
workorder.state = 'ready'
|
||||
else:
|
||||
workorder.state = 'waiting'
|
||||
# production_programming = self.env['mrp.production'].search(
|
||||
# [('origin', '=', self.production_id.origin)], order='name asc')
|
||||
# production_no_remanufacture = production_programming.filtered(
|
||||
# lambda a: a.is_remanufacture is False)
|
||||
# production_list = [production.name for production in production_programming]
|
||||
# purchase_orders = self.env['purchase.order'].search(
|
||||
# [('origin', 'ilike', ','.join(production_list))])
|
||||
# for line in purchase_orders.order_line:
|
||||
# if (
|
||||
# line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id
|
||||
# and line.product_qty == len(production_no_remanufacture)):
|
||||
# if all(pur_order.state == 'purchase' for pur_order in purchase_orders):
|
||||
# workorder.state = 'ready'
|
||||
# else:
|
||||
# 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'
|
||||
else:
|
||||
workorder.state = 'waiting'
|
||||
|
||||
# re_work = self.env['mrp.workorder'].search([('production_id', '=', workorder.production_id.id),
|
||||
# ('processing_panel', '=', workorder.processing_panel),
|
||||
@@ -1241,12 +1251,13 @@ class ResMrpWorkOrder(models.Model):
|
||||
# 表面工艺外协出库单
|
||||
if self.routing_type == '表面工艺':
|
||||
if self.is_subcontract is True:
|
||||
move_out = self.env['stock.move'].search(
|
||||
[('location_id', '=', self.env['stock.location'].search(
|
||||
[('barcode', 'ilike', 'WH-PREPRODUCTION')]).id),
|
||||
('location_dest_id', '=', self.env['stock.location'].search(
|
||||
[('barcode', 'ilike', 'VL-SPOC')]).id),
|
||||
('origin', '=', self.production_id.name), ('state', 'not in', ['cancel', 'done'])])
|
||||
move_out = self.move_subcontract_workorder_ids[1]
|
||||
# move_out = self.env['stock.move'].search(
|
||||
# [('location_id', '=', self.env['stock.location'].search(
|
||||
# [('barcode', 'ilike', 'WH-PREPRODUCTION')]).id),
|
||||
# ('location_dest_id', '=', self.env['stock.location'].search(
|
||||
# [('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)])
|
||||
@@ -1254,6 +1265,21 @@ class ResMrpWorkOrder(models.Model):
|
||||
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))
|
||||
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':
|
||||
@@ -1526,6 +1552,8 @@ class ResMrpWorkOrder(models.Model):
|
||||
'default_confirm_button': '确认解除',
|
||||
# 'default_feeder_station_start_id': feeder_station_start_id,
|
||||
}}
|
||||
|
||||
move_subcontract_workorder_ids = fields.One2many('stock.move', 'subcontract_workorder_id', string='组件')
|
||||
|
||||
|
||||
class CNCprocessing(models.Model):
|
||||
|
||||
Reference in New Issue
Block a user