新增出库单验证前置和后置条件,外协工单点击完成时生成询价单
This commit is contained in:
@@ -479,53 +479,38 @@ class ResMrpWorkOrder(models.Model):
|
||||
if self.date_planned_finished and self.date_planned_finished < start_date:
|
||||
vals['date_planned_finished'] = start_date
|
||||
return self.write(vals)
|
||||
# 外协出库单,从“正在等待”变为“就绪”状态
|
||||
if self.is_subcontract is True:
|
||||
picking_out = self.env['stock.picking'].search([('id', '=', self.picking_out_id.id)])
|
||||
if picking_out:
|
||||
picking_out.write({'state': 'assigned'})
|
||||
else:
|
||||
raise UserError(_('请先完成上一步工单'))
|
||||
|
||||
def button_finish(self):
|
||||
end_date = datetime.now()
|
||||
for workorder in self:
|
||||
if workorder.state in ('done', 'cancel'):
|
||||
continue
|
||||
workorder.end_all()
|
||||
vals = {
|
||||
'qty_produced': workorder.qty_produced or workorder.qty_producing or workorder.qty_production,
|
||||
'state': 'done',
|
||||
'date_finished': end_date,
|
||||
'date_planned_finished': end_date,
|
||||
'costs_hour': workorder.workcenter_id.costs_hour
|
||||
}
|
||||
if not workorder.date_start:
|
||||
vals['date_start'] = end_date
|
||||
if not workorder.date_planned_start or end_date < workorder.date_planned_start:
|
||||
vals['date_planned_start'] = end_date
|
||||
workorder.with_context(bypass_duration_calculation=True).write(vals)
|
||||
self.env.cr.commit()
|
||||
finish_workorder_count = self.env['mrp.workorder'].search_count(
|
||||
[('production_id', '=', workorder.production_id.id),
|
||||
('is_subcontract', '=', True)])
|
||||
subcontract_workorder_count = self.env['mrp.workorder'].search_count(
|
||||
[('production_id', '=', workorder.production_id.id), ('is_subcontract', '=', True),
|
||||
('state', '=', 'done')])
|
||||
if finish_workorder_count > 0 and subcontract_workorder_count > 0:
|
||||
subcontract_workorder = self.env['mrp.workorder'].search(
|
||||
[('production_id', '=', workorder.production_id.id), ('is_subcontract', '=', True),
|
||||
('state', '=', 'done')])
|
||||
for item in subcontract_workorder:
|
||||
order_line_ids = []
|
||||
server_product = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', item.surface_technics_parameters_id.id),
|
||||
('categ_type', '=', '服务'), ('detailed_type', '=', 'service')])
|
||||
if self.picking_out_id:
|
||||
picking_out = self.env['stock.picking'].search([('id', '=', self.picking_out_id.id)])
|
||||
if picking_out.workorder_out_id:
|
||||
order_line_ids = []
|
||||
for item in picking_out.workorder_out_id:
|
||||
server_product = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', item.surface_technics_parameters_id.id),
|
||||
('detailed_type', '=', 'service')])
|
||||
if server_product:
|
||||
order_line_ids.append((0, 0, {
|
||||
'product_id': server_product.product_variant_id.id,
|
||||
'product_qty': 1,
|
||||
'product_uom': server_product.uom_id.id
|
||||
}))
|
||||
self.env['purchase.order'].create({
|
||||
'partner_id': server_product.seller_ids.partner_id.id,
|
||||
'state': 'draft',
|
||||
'order_line': order_line_ids,
|
||||
})
|
||||
else:
|
||||
raise UserError(
|
||||
'请先在产品中配置表面工艺为%s相关的外协服务产品' % item.surface_technics_parameters_id.name)
|
||||
self.env['purchase.order'].create({
|
||||
'partner_id': server_product.seller_ids.partner_id.id,
|
||||
'state': 'draft',
|
||||
'order_line': order_line_ids,
|
||||
})
|
||||
super().button_finish()
|
||||
|
||||
|
||||
class CNCprocessing(models.Model):
|
||||
@@ -705,4 +690,4 @@ class SfWorkOrderBarcodes(models.Model):
|
||||
pass
|
||||
|
||||
else:
|
||||
self.pro_code_ok = workorder.pro_code_is_ok(barcode)
|
||||
self.pro_code_ok = workorder.pro_code_is_ok(barcode)
|
||||
|
||||
Reference in New Issue
Block a user