优化及调试表面工艺外协出入库单,‘胚料’修改为‘坯料’
This commit is contained in:
@@ -6,11 +6,11 @@ class ModelType(models.Model):
|
||||
_description = '模型类型'
|
||||
|
||||
name = fields.Char('名称')
|
||||
embryo_tolerance = fields.Integer('胚料容余')
|
||||
embryo_tolerance = fields.Integer('坯料容余')
|
||||
product_routing_tmpl_ids = fields.One2many('sf.product.model.type.routing.sort', 'product_model_type_id',
|
||||
'成品工序模板')
|
||||
embryo_routing_tmpl_ids = fields.One2many('sf.embryo.model.type.routing.sort', 'embryo_model_type_id',
|
||||
'胚料工序模板')
|
||||
'坯料工序模板')
|
||||
surface_technics_routing_tmpl_ids = fields.One2many('sf.surface_technics.model.type.routing.sort',
|
||||
'surface_technics_model_type_id',
|
||||
'表面工艺工序模板')
|
||||
@@ -41,7 +41,7 @@ class ProductModelTypeRoutingSort(models.Model):
|
||||
|
||||
class EmbryoModelTypeRoutingSort(models.Model):
|
||||
_name = 'sf.embryo.model.type.routing.sort'
|
||||
_description = '胚料工序排序'
|
||||
_description = '坯料工序排序'
|
||||
|
||||
sequence = fields.Integer('Sequence')
|
||||
route_workcenter_id = fields.Many2one('mrp.routing.workcenter')
|
||||
@@ -58,7 +58,7 @@ class EmbryoModelTypeRoutingSort(models.Model):
|
||||
embryo_model_type_id = fields.Many2one('sf.model.type')
|
||||
|
||||
_sql_constraints = [
|
||||
('route_model_type_uniq', 'unique (route_workcenter_id,embryo_model_type_id)', '胚料工序不能重复!')
|
||||
('route_model_type_uniq', 'unique (route_workcenter_id,embryo_model_type_id)', '坯料工序不能重复!')
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -138,31 +138,35 @@ class MrpProduction(models.Model):
|
||||
surface_technics_arr.append(item.route_workcenter_id.surface_technics_id.id)
|
||||
route_workcenter_arr.append(item.route_workcenter_id.id)
|
||||
if surface_technics_arr:
|
||||
production_process = self.env['sf.production.process.category'].search(
|
||||
production_process_category = self.env['sf.production.process.category'].search(
|
||||
[('production_process_ids.id', 'in', surface_technics_arr)],
|
||||
order='sequence asc'
|
||||
)
|
||||
if production_process:
|
||||
for p in production_process:
|
||||
for pitem in p.production_process_ids:
|
||||
if pitem.id in surface_technics_arr:
|
||||
for param in production.product_id.model_process_parameters_ids:
|
||||
process_parameter = self.env['sf.production.process.parameter'].search(
|
||||
[('process_id.id', '=', pitem.id), ('id', '=', param.id)])
|
||||
# 产品为表面工艺服务的供应商
|
||||
product_production_process = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', process_parameter.id)])
|
||||
if process_parameter:
|
||||
for ritem in route_workcenter_arr:
|
||||
route_production_process = self.env['mrp.routing.workcenter'].search(
|
||||
[('surface_technics_id', '=', pitem.id), ('id', '=', ritem)])
|
||||
if route_production_process:
|
||||
workorders_values.append(
|
||||
self.env['mrp.workorder']._json_workorder_surface_process_str(
|
||||
production, route_production_process,
|
||||
process_parameter,
|
||||
product_production_process.seller_ids[0].id))
|
||||
elif production.product_id.categ_id.type == '胚料':
|
||||
#用filter刷选表面工艺id'是否存在工艺类别对象里
|
||||
if production_process_category:
|
||||
for p in production_process_category:
|
||||
production_process = p.production_process_ids.filtered(
|
||||
lambda pp: pp.id in surface_technics_arr)
|
||||
if production_process:
|
||||
process_parameter = production.product_id.model_process_parameters_ids.filtered(
|
||||
lambda pm: pm.process_id.id == production_process.id)
|
||||
if process_parameter:
|
||||
# 产品为表面工艺服务的供应商
|
||||
product_production_process = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', process_parameter.id)])
|
||||
if product_production_process:
|
||||
route_production_process = self.env[
|
||||
'mrp.routing.workcenter'].search(
|
||||
[('surface_technics_id', '=', production_process.id),
|
||||
('id', 'in', route_workcenter_arr)])
|
||||
if route_production_process:
|
||||
workorders_values.append(
|
||||
self.env[
|
||||
'mrp.workorder']._json_workorder_surface_process_str(
|
||||
production, route_production_process,
|
||||
process_parameter,
|
||||
product_production_process.seller_ids[0].partner_id.id))
|
||||
elif production.product_id.categ_id.type == '坯料':
|
||||
embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
|
||||
[('embryo_model_type_id', '=', production.product_id.embryo_model_type_id.id)],
|
||||
order='sequence asc'
|
||||
@@ -171,23 +175,49 @@ class MrpProduction(models.Model):
|
||||
workorders_values.append(
|
||||
self.env['mrp.workorder'].json_workorder_str('', production, route))
|
||||
production.workorder_ids = workorders_values
|
||||
aa = self.env['mrp.workorder'].get_no_data(production.id)
|
||||
if aa:
|
||||
consecutive_workorders = []
|
||||
m =0
|
||||
sorted_workorders = sorted(aa, key=lambda w: w.id)
|
||||
for i in range(len(sorted_workorders) - 1):
|
||||
if sorted_workorders[i].supplier_id == sorted_workorders[i + 1].supplier_id and \
|
||||
sorted_workorders[i].id == sorted_workorders[i + 1].id - 1:
|
||||
consecutive_workorders.append(sorted_workorders[i])
|
||||
consecutive_workorders.append(sorted_workorders[i + 1])
|
||||
m+1
|
||||
process_parameter_workorder = self.env['mrp.workorder'].search(
|
||||
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', production.id)])
|
||||
if process_parameter_workorder:
|
||||
is_pick = False
|
||||
consecutive_workorders = []
|
||||
m = 0
|
||||
sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.id)
|
||||
for i in range(len(sorted_workorders) - 1):
|
||||
if m == 0:
|
||||
is_pick = False
|
||||
# if sorted_workorders[i].id in consecutive_workorders:
|
||||
# consecutive_workorders = [x for x in consecutive_workorders if x not in sorted_workorders[i].id]
|
||||
# continue
|
||||
if sorted_workorders[i].supplier_id == sorted_workorders[i + 1].supplier_id and \
|
||||
sorted_workorders[i].id == sorted_workorders[i + 1].id - 1:
|
||||
if sorted_workorders[i] not in consecutive_workorders:
|
||||
consecutive_workorders.append(sorted_workorders[i])
|
||||
consecutive_workorders.append(sorted_workorders[i + 1])
|
||||
m += 1
|
||||
continue
|
||||
else:
|
||||
if m == len(consecutive_workorders)-1 and m != 0:
|
||||
self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production)
|
||||
if sorted_workorders[i] in consecutive_workorders:
|
||||
is_pick = True
|
||||
consecutive_workorders = []
|
||||
m = 0
|
||||
# 当前面的连续工序生成对应的外协出入库单再生成当前工序的外协出入库单
|
||||
if is_pick is False:
|
||||
self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production)
|
||||
if m == len(consecutive_workorders)-1 and m != 0:
|
||||
self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production)
|
||||
if sorted_workorders[i] in consecutive_workorders:
|
||||
is_pick = True
|
||||
consecutive_workorders = []
|
||||
m = 0
|
||||
if m == len(consecutive_workorders) - 1 and m != 0:
|
||||
self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production)
|
||||
if is_pick is False:
|
||||
self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production)
|
||||
for workorder in production.workorder_ids:
|
||||
workorder.duration_expected = workorder._get_duration_expected()
|
||||
|
||||
|
||||
# 在之前的销售单上重新生成制造订单
|
||||
def create_production1_values(self, production):
|
||||
production_values_str = {'origin': production.origin,
|
||||
@@ -210,6 +240,20 @@ class MrpProduction(models.Model):
|
||||
'user_id': production.user_id.id}
|
||||
return production_values_str
|
||||
|
||||
def _get_stock_move_values_Res(self,item,location_src_id,location_dest_id):
|
||||
move_values = {
|
||||
'name': item.name if item.name else '/',
|
||||
'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,
|
||||
'origin': item.origin,
|
||||
'picking_type_id': self.picking_type_id.id,
|
||||
}
|
||||
return move_values
|
||||
|
||||
# 工单排序
|
||||
def _reset_work_order_sequence1(self, k):
|
||||
sequen = 0
|
||||
|
||||
@@ -28,7 +28,7 @@ class ResMrpRoutingWorkcenter(models.Model):
|
||||
company_id = fields.Many2one('res.company', compute="get_company_id", related=False)
|
||||
|
||||
|
||||
# 排产的时候, 根据胚料的长宽高比对一下机床的最大加工尺寸.不符合就不要分配给这个加工中心(机床).
|
||||
# 排产的时候, 根据坯料的长宽高比对一下机床的最大加工尺寸.不符合就不要分配给这个加工中心(机床).
|
||||
# 工单对应的工作中心,根据工序中的工作中心去匹配,
|
||||
# 如果只配置了一个工作中心,则默认采用该工作中心;
|
||||
# 如果有多个工作中心,
|
||||
|
||||
@@ -54,7 +54,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
programming_state = fields.Char('编程状态')
|
||||
cnc_worksheet = fields.Binary(
|
||||
'工作指令', readonly=True)
|
||||
material_center_point = fields.Char(string='胚料中心点')
|
||||
material_center_point = fields.Char(string='坯料中心点')
|
||||
X1_axis = fields.Float(default=0)
|
||||
Y1_axis = fields.Float(default=0)
|
||||
Z1_axis = fields.Float(default=0)
|
||||
@@ -93,7 +93,8 @@ class ResMrpWorkOrder(models.Model):
|
||||
glb_file = fields.Binary("glb模型文件")
|
||||
is_subcontract = fields.Boolean(string='是否外协')
|
||||
surface_technics_parameters_id = fields.Many2one('sf.production.process.parameter', string="表面工艺可选参数")
|
||||
picking_id = fields.Many2one('stock.picking', string='外协出入库单')
|
||||
picking_in_id = fields.Many2one('stock.picking', string='外协入库单')
|
||||
picking_out_id = fields.Many2one('stock.picking', string='外协出库单')
|
||||
supplier_id = fields.Integer('供应商Id')
|
||||
|
||||
def get_no_data(self, production_id):
|
||||
|
||||
@@ -12,13 +12,6 @@ from odoo.exceptions import UserError
|
||||
class StockRule(models.Model):
|
||||
_inherit = 'stock.rule'
|
||||
|
||||
# @api.model
|
||||
# def _run_pull(self, procurements):
|
||||
# res = super(StockRule, self)._run_pull(procurements)
|
||||
# # process_parameter_workorder = self.env['mrp.workorder'].search(
|
||||
# # [('surface_technics_parameters_id', '!=', False), ('production_id', '=', self.production_id)])
|
||||
# stock_move = self.env['stock.move'].search([('raw_material_production_id', '=', self.id)])
|
||||
|
||||
@api.model
|
||||
def _run_pull(self, procurements):
|
||||
moves_values_by_company = defaultdict(list)
|
||||
@@ -190,54 +183,6 @@ class StockRule(models.Model):
|
||||
subtype_id=self.env.ref('mail.mt_note').id)
|
||||
return True
|
||||
|
||||
def create_outcontract_stock_move(self, sorted_workorders, item):
|
||||
outcontract_stock_move = self.env['stock.move'].search(
|
||||
[('workorder_id', '=', sorted_workorders.id), ('production_id', '=', item.id)])
|
||||
if not outcontract_stock_move:
|
||||
location_id = self.env.ref(
|
||||
'sf_manufacturing.stock_location_locations_virtual_outcontract').id,
|
||||
location_dest_id = self.env['stock.location'].search(
|
||||
[('barcode', '=', 'WH-PREPRODUCTION')]).id,
|
||||
outcontract_picking_in = self.env['stock.rule'].create_outcontract_picking(item,
|
||||
location_id,
|
||||
location_dest_id)
|
||||
outcontract_picking_in.write({'workorder_id': outcontract_picking_in.id})
|
||||
outcontract_picking_out = self.env['stock.rule'].create_outcontract_picking(item,
|
||||
location_dest_id,
|
||||
location_id)
|
||||
outcontract_picking_out.write({'workorder_id': outcontract_picking_out.id})
|
||||
|
||||
# 生成外协出入库单
|
||||
def create_outcontract_picking(self, item, location_src_id, location_dest_id):
|
||||
moves_values_by_company = defaultdict(list)
|
||||
list2 = []
|
||||
Procurement = namedtuple('Procurement', ['product_id', 'product_qty',
|
||||
'product_uom', 'location_id', 'location_dest_id', 'name', 'origin',
|
||||
'company_id',
|
||||
'values'])
|
||||
s = Procurement(product_id=item.bom_id.product_id, product_qty=1.0, product_uom=item.product_uom,
|
||||
location_id=location_src_id,
|
||||
location_dest_id=location_dest_id,
|
||||
name=item.name,
|
||||
origin=item.origin,
|
||||
company_id=item.company_id,
|
||||
values=item.values,
|
||||
)
|
||||
item1 = list(item)
|
||||
item1[0] = s
|
||||
list2.append(tuple(item1))
|
||||
for procurement in list2:
|
||||
move_values = self.env['stock.rule']._get_stock_move_values(*procurement)
|
||||
moves_values_by_company[procurement.company_id.id].append(move_values)
|
||||
for company_id, moves_values in moves_values_by_company.items():
|
||||
moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
|
||||
moves_values)
|
||||
new_picking = True
|
||||
picking = self.env['stock.picking'].create(moves._get_new_picking_values())
|
||||
moves.write({'picking_id': picking.id})
|
||||
moves._assign_picking_post_process(new=new_picking)
|
||||
return picking
|
||||
|
||||
|
||||
class ProductionLot(models.Model):
|
||||
_inherit = 'stock.lot'
|
||||
@@ -288,72 +233,31 @@ class ProductionLot(models.Model):
|
||||
class ResStockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
workorder_id = fields.One2many('mrp.workorder', 'picking_id')
|
||||
workorder_in_id = fields.One2many('mrp.workorder', 'picking_in_id')
|
||||
workorder_out_id = fields.One2many('mrp.workorder', 'picking_out_id')
|
||||
|
||||
def create_outcontract_picking(self, sorted_workorders_arr, item):
|
||||
m = 0
|
||||
for sorted_workorders in sorted_workorders_arr:
|
||||
if m == 0:
|
||||
outcontract_stock_move = self.env['stock.move'].search(
|
||||
[('workorder_id', '=', sorted_workorders.id), ('production_id', '=', item.id)])
|
||||
if not outcontract_stock_move:
|
||||
location_id = self.env.ref(
|
||||
'sf_manufacturing.stock_location_locations_virtual_outcontract').id,
|
||||
location_dest_id = self.env['stock.location'].search(
|
||||
[('barcode', '=', 'WH-PREPRODUCTION')]).id,
|
||||
moves_in = self.env['stock.move'].sudo().create(
|
||||
item._get_stock_move_values_Res(item, location_id, location_dest_id))
|
||||
moves_out = self.env['stock.move'].sudo().create(
|
||||
item._get_stock_move_values_Res(item, location_dest_id, location_id))
|
||||
new_picking = True
|
||||
picking_in = self.env['stock.picking'].create(moves_in._get_new_picking_values())
|
||||
picking_out = self.env['stock.picking'].create(moves_out._get_new_picking_values())
|
||||
moves_in.write({'picking_id': picking_in.id})
|
||||
moves_out.write({'picking_id': picking_out.id})
|
||||
moves_in._assign_picking_post_process(new=new_picking)
|
||||
moves_out._assign_picking_post_process(new=new_picking)
|
||||
m += 1
|
||||
sorted_workorders.write({'picking_in_id': picking_in.id, 'picking_out_id': picking_out.id})
|
||||
|
||||
class ResPurchaseOrder(models.Model):
|
||||
_inherit = 'purchase.order'
|
||||
|
||||
# 外协出库、入库单
|
||||
def _prepare_picking_outcontract(self, sequence_code):
|
||||
# if not self.group_id:
|
||||
# self.group_id = self.group_id.create({
|
||||
# 'name': self.name,
|
||||
# 'partner_id': self.partner_id.id
|
||||
# })
|
||||
# if not self.partner_id.property_stock_supplier.id:
|
||||
# raise UserError(_("You must set a Vendor Location for this partner %s", self.partner_id.name))
|
||||
|
||||
picking_type_id_oc = self.env['stock.picking.type'].search([('sequence_code', '=', sequence_code)])
|
||||
return {
|
||||
'picking_type_id': picking_type_id_oc.id if picking_type_id_oc else self.picking_type_id.id,
|
||||
'partner_id': self.partner_id.id,
|
||||
'user_id': False,
|
||||
'date': self.date_order,
|
||||
'origin': self.name,
|
||||
'location_dest_id': self._get_destination_location(),
|
||||
'location_id': self.partner_id.property_stock_supplier.id,
|
||||
'company_id': self.company_id.id,
|
||||
}
|
||||
|
||||
def _create_picking_outcontract(self):
|
||||
StockPicking = self.env['stock.picking']
|
||||
for order in self.filtered(lambda po: po.state in ('purchase', 'done')):
|
||||
if any(product.type in ['product', 'consu'] for product in order.order_line.product_id):
|
||||
order = order.with_company(order.company_id)
|
||||
pickings = order.picking_ids.filtered(lambda x: x.state not in ('done', 'cancel'))
|
||||
if not pickings:
|
||||
res = order._prepare_picking_outcontract()
|
||||
picking = StockPicking.with_user(SUPERUSER_ID).create(res)
|
||||
pickings = picking
|
||||
else:
|
||||
picking = pickings[0]
|
||||
moves = order.order_line._create_stock_moves(picking)
|
||||
moves = moves.filtered(lambda x: x.state not in ('done', 'cancel'))._action_confirm()
|
||||
seq = 0
|
||||
for move in sorted(moves, key=lambda move: move.date):
|
||||
seq += 5
|
||||
move.sequence = seq
|
||||
moves._action_assign()
|
||||
# Get following pickings (created by push rules) to confirm them as well.
|
||||
forward_pickings = self.env['stock.picking']._get_impacted_pickings(moves)
|
||||
(pickings | forward_pickings).action_confirm()
|
||||
picking.message_post_with_view('mail.message_origin_link',
|
||||
values={'self': picking, 'origin': order},
|
||||
subtype_id=self.env.ref('mail.mt_note').id)
|
||||
return True
|
||||
|
||||
|
||||
class ResPurchaseOrderLine(models.Model):
|
||||
_inherit = 'purchase.order.line'
|
||||
|
||||
def _create_stock_moves(self, picking):
|
||||
values = []
|
||||
for line in self.filtered(lambda l: not l.display_type):
|
||||
for val in line._prepare_stock_moves(picking):
|
||||
# val['production_id'] = 10
|
||||
val['is_subcontract'] = True
|
||||
values.append(val)
|
||||
line.move_dest_ids.created_purchase_line_id = False
|
||||
|
||||
return self.env['stock.move'].create(values)
|
||||
|
||||
Reference in New Issue
Block a user