新增出库单验证前置和后置条件,外协工单点击完成时生成询价单
This commit is contained in:
@@ -339,7 +339,6 @@ class MrpProduction(models.Model):
|
|||||||
current_sequence += 1
|
current_sequence += 1
|
||||||
if work.name == '获取CNC加工程序':
|
if work.name == '获取CNC加工程序':
|
||||||
work.button_start()
|
work.button_start()
|
||||||
work.button_finish()
|
|
||||||
work.fetchCNC()
|
work.fetchCNC()
|
||||||
|
|
||||||
# 创建工单并进行排序
|
# 创建工单并进行排序
|
||||||
|
|||||||
@@ -479,53 +479,38 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
if self.date_planned_finished and self.date_planned_finished < start_date:
|
if self.date_planned_finished and self.date_planned_finished < start_date:
|
||||||
vals['date_planned_finished'] = start_date
|
vals['date_planned_finished'] = start_date
|
||||||
return self.write(vals)
|
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:
|
else:
|
||||||
raise UserError(_('请先完成上一步工单'))
|
raise UserError(_('请先完成上一步工单'))
|
||||||
|
|
||||||
def button_finish(self):
|
def button_finish(self):
|
||||||
end_date = datetime.now()
|
if self.picking_out_id:
|
||||||
for workorder in self:
|
picking_out = self.env['stock.picking'].search([('id', '=', self.picking_out_id.id)])
|
||||||
if workorder.state in ('done', 'cancel'):
|
if picking_out.workorder_out_id:
|
||||||
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 = []
|
order_line_ids = []
|
||||||
|
for item in picking_out.workorder_out_id:
|
||||||
server_product = self.env['product.template'].search(
|
server_product = self.env['product.template'].search(
|
||||||
[('server_product_process_parameters_id', '=', item.surface_technics_parameters_id.id),
|
[('server_product_process_parameters_id', '=', item.surface_technics_parameters_id.id),
|
||||||
('categ_type', '=', '服务'), ('detailed_type', '=', 'service')])
|
('detailed_type', '=', 'service')])
|
||||||
|
if server_product:
|
||||||
order_line_ids.append((0, 0, {
|
order_line_ids.append((0, 0, {
|
||||||
'product_id': server_product.product_variant_id.id,
|
'product_id': server_product.product_variant_id.id,
|
||||||
'product_qty': 1,
|
'product_qty': 1,
|
||||||
'product_uom': server_product.uom_id.id
|
'product_uom': server_product.uom_id.id
|
||||||
}))
|
}))
|
||||||
|
else:
|
||||||
|
raise UserError(
|
||||||
|
'请先在产品中配置表面工艺为%s相关的外协服务产品' % item.surface_technics_parameters_id.name)
|
||||||
self.env['purchase.order'].create({
|
self.env['purchase.order'].create({
|
||||||
'partner_id': server_product.seller_ids.partner_id.id,
|
'partner_id': server_product.seller_ids.partner_id.id,
|
||||||
'state': 'draft',
|
'state': 'draft',
|
||||||
'order_line': order_line_ids,
|
'order_line': order_line_ids,
|
||||||
})
|
})
|
||||||
|
super().button_finish()
|
||||||
|
|
||||||
|
|
||||||
class CNCprocessing(models.Model):
|
class CNCprocessing(models.Model):
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from re import findall as regex_findall
|
|||||||
from re import split as regex_split
|
from re import split as regex_split
|
||||||
from odoo import SUPERUSER_ID, _, api, fields, models
|
from odoo import SUPERUSER_ID, _, api, fields, models
|
||||||
from odoo.tools import float_compare
|
from odoo.tools import float_compare
|
||||||
|
import logging
|
||||||
|
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
@@ -238,7 +239,8 @@ class StockPicking(models.Model):
|
|||||||
|
|
||||||
# 设置外协出入单的名称
|
# 设置外协出入单的名称
|
||||||
def _get_name_Res(self, rescode):
|
def _get_name_Res(self, rescode):
|
||||||
count = self.env['ir.sequence'].search_count([('prefix', 'like', rescode)])
|
count = self.env['stock.picking'].search_count([('name', 'like', rescode)])
|
||||||
|
logging.info('count:' + str(count))
|
||||||
if not count:
|
if not count:
|
||||||
num = "%04d" % 1
|
num = "%04d" % 1
|
||||||
else:
|
else:
|
||||||
@@ -246,6 +248,21 @@ class StockPicking(models.Model):
|
|||||||
num = "%04d" % m
|
num = "%04d" % m
|
||||||
return '%s%s' % (rescode, num)
|
return '%s%s' % (rescode, num)
|
||||||
|
|
||||||
|
def button_validate(self):
|
||||||
|
if self.workorder_out_id:
|
||||||
|
workorder_in = self.workorder_out_id.filtered(lambda p: p.state == 'progress' and p.is_subcontract is True)
|
||||||
|
if workorder_in:
|
||||||
|
picking_in = self.env['stock.picking'].search([('id', '=', workorder_in.picking_in_id.id)])
|
||||||
|
if picking_in:
|
||||||
|
picking_in.write({'state': 'assigned'})
|
||||||
|
else:
|
||||||
|
workorder_subcontract = self.workorder_out_id.filtered(
|
||||||
|
lambda p: p.state == 'pending' and p.is_subcontract is True)
|
||||||
|
if workorder_subcontract:
|
||||||
|
raise UserError(_('该出库单对应的工单还未开始,不能进行验证操作!'))
|
||||||
|
res = super().button_validate()
|
||||||
|
return res
|
||||||
|
|
||||||
# 创建 外协出库入单
|
# 创建 外协出库入单
|
||||||
def create_outcontract_picking(self, sorted_workorders_arr, item):
|
def create_outcontract_picking(self, sorted_workorders_arr, item):
|
||||||
m = 0
|
m = 0
|
||||||
@@ -270,7 +287,7 @@ class StockPicking(models.Model):
|
|||||||
outcontract_picking_type_out))
|
outcontract_picking_type_out))
|
||||||
new_picking = True
|
new_picking = True
|
||||||
picking_in = self.env['stock.picking'].create(
|
picking_in = self.env['stock.picking'].create(
|
||||||
moves_in._get_new_picking_values_Res(item, sorted_workorders,'WH/OCIN/'))
|
moves_in._get_new_picking_values_Res(item, sorted_workorders, 'WH/OCIN/'))
|
||||||
picking_out = self.env['stock.picking'].create(
|
picking_out = self.env['stock.picking'].create(
|
||||||
moves_out._get_new_picking_values_Res(item, sorted_workorders, 'WH/OCOUT/'))
|
moves_out._get_new_picking_values_Res(item, sorted_workorders, 'WH/OCOUT/'))
|
||||||
moves_in.write({'picking_id': picking_in.id})
|
moves_in.write({'picking_id': picking_in.id})
|
||||||
@@ -285,6 +302,7 @@ class ReStockMove(models.Model):
|
|||||||
_inherit = 'stock.move'
|
_inherit = 'stock.move'
|
||||||
|
|
||||||
def _get_new_picking_values_Res(self, item, sorted_workorders, rescode):
|
def _get_new_picking_values_Res(self, item, sorted_workorders, rescode):
|
||||||
|
logging.info('new_picking-rescode: %s' % rescode)
|
||||||
return {
|
return {
|
||||||
'name': self.env['stock.picking']._get_name_Res(rescode),
|
'name': self.env['stock.picking']._get_name_Res(rescode),
|
||||||
'origin': item.name,
|
'origin': item.name,
|
||||||
@@ -295,5 +313,6 @@ class ReStockMove(models.Model):
|
|||||||
'picking_type_id': self.mapped('picking_type_id').id,
|
'picking_type_id': self.mapped('picking_type_id').id,
|
||||||
'location_id': self.mapped('location_id').id,
|
'location_id': self.mapped('location_id').id,
|
||||||
'location_dest_id': self.mapped('location_dest_id').id,
|
'location_dest_id': self.mapped('location_dest_id').id,
|
||||||
'state': 'draft',
|
'state': 'confirmed',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user