Accept Merge Request #1563: (feature/修复报废调拨 -> develop)

Merge Request: 修复制造订单生成采购

Created By: @杨金灵
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @杨金灵
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/1563
This commit is contained in:
杨金灵
2024-11-28 10:03:05 +08:00
committed by Coding
10 changed files with 93 additions and 68 deletions

View File

@@ -843,7 +843,7 @@ class MrpProduction(models.Model):
# workorder.picking_ids.move_ids = False # workorder.picking_ids.move_ids = False
workorder.picking_ids = False workorder.picking_ids = False
purchase_order = self.env['purchase.order'].search( purchase_order = self.env['purchase.order'].search(
[('state', '=', 'draft'), ('origin', '=', ','.join(production_process)), [('state', '=', 'draft'), ('origin', '=', item.name),
('purchase_type', '=', 'consignment')]) ('purchase_type', '=', 'consignment')])
for line in purchase_order.order_line: for line in purchase_order.order_line:
server_template = self.env['product.template'].search( server_template = self.env['product.template'].search(
@@ -851,7 +851,7 @@ class MrpProduction(models.Model):
('detailed_type', '=', 'service')]) ('detailed_type', '=', 'service')])
purchase_order_line = self.env['purchase.order.line'].search( purchase_order_line = self.env['purchase.order.line'].search(
[('product_id', '=', server_template.product_variant_id.id), ('id', '=', line.id), [('product_id', '=', server_template.product_variant_id.id), ('id', '=', line.id),
('product_qty', '=', len(production_process))], limit=1, order='id desc') ('product_qty', '=', 1)], limit=1, order='id desc')
if purchase_order_line: if purchase_order_line:
line.unlink() line.unlink()
@@ -1320,11 +1320,10 @@ class MrpProduction(models.Model):
move = self.env['stock.move'].search([('origin', '=', productions.name)], order='id desc') move = self.env['stock.move'].search([('origin', '=', productions.name)], order='id desc')
for mo in move: for mo in move:
domain = [] domain = []
if mo.procure_method == 'make_to_order' and mo.name != productions.name: if mo.location_id.barcode == 'WH-POSTPRODUCTION' and mo.rule_id.picking_type_id.barcode == 'PC':
if mo.name == '/': domain = [('barcode', '=', 'WH-PC'), ('sequence_code', '=', 'PC')]
domain = [('barcode', '=', 'WH-PC'), ('sequence_code', '=', 'PC')] elif mo.location_id.barcode == 'PL' and mo.rule_id.picking_type_id.barcode == 'INT':
elif mo.name == '': domain = [('barcode', '=', 'WH-INTERNAL'), ('sequence_code', '=', 'INT')]
domain = [('barcode', '=', 'WH-INTERNAL'), ('sequence_code', '=', 'INT')]
if domain: if domain:
picking_type = self.env['stock.picking.type'].search(domain) picking_type = self.env['stock.picking.type'].search(domain)
mo.write({'picking_type_id': picking_type.id}) mo.write({'picking_type_id': picking_type.id})

View File

@@ -86,9 +86,12 @@ class ResMrpRoutingWorkcenter(models.Model):
@api.model @api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
if self._context.get('production_id'): if self._context.get('production_id'):
route_ids = []
technology_design = self.env['sf.technology.design'].search( technology_design = self.env['sf.technology.design'].search(
[('production_id', '=', self._context.get('production_id'))]) [('production_id', '=', self._context.get('production_id'))])
route_ids = [t.route_id.id for t in technology_design] for t in technology_design.filtered(lambda a: a.routing_tag == 'special'):
domain = [('id', 'not in', route_ids)] if not t.process_parameters_id:
route_ids.append(t.route_id.surface_technics_id.id)
domain = [('id', 'not in', route_ids), ('routing_tag', '=', 'special')]
return self._search(domain, limit=limit, access_rights_uid=name_get_uid) return self._search(domain, limit=limit, access_rights_uid=name_get_uid)
return super()._name_search(name, args, operator, limit, name_get_uid) return super()._name_search(name, args, operator, limit, name_get_uid)

View File

@@ -241,9 +241,9 @@ class ResMrpWorkOrder(models.Model):
('production_id', '=', workorder.production_id.id)]) ('production_id', '=', workorder.production_id.id)])
if previous_workorder: if previous_workorder:
if previous_workorder.supplier_id != workorder.supplier_id: if previous_workorder.supplier_id != workorder.supplier_id:
process_product = self.env['product.template']._get_process_parameters_product( # process_product = self.env['product.template']._get_process_parameters_product(
previous_workorder.surface_technics_parameters_id) # previous_workorder.surface_technics_parameters_id)
domain += [('partner_id', '=', process_product.partner_id.id)] domain += [('surface_technics_parameters_id', '=', workorder.surface_technics_parameters_id.id)]
else: else:
domain += [('surface_technics_parameters_id', '=', workorder.surface_technics_parameters_id.id)] domain += [('surface_technics_parameters_id', '=', workorder.surface_technics_parameters_id.id)]
picking_ids = self.env['stock.picking'].search(domain, order='id asc') picking_ids = self.env['stock.picking'].search(domain, order='id asc')
@@ -270,55 +270,57 @@ class ResMrpWorkOrder(models.Model):
def _compute_surface_technics_purchase_ids(self): def _compute_surface_technics_purchase_ids(self):
for order in self: for order in self:
if order.routing_type == '表面工艺': if order.routing_type == '表面工艺':
if order.production_id.production_type == '自动化产线加工': # if order.production_id.production_type == '自动化产线加工':
domain = [('programming_no', '=', order.production_id.programming_no)] # domain = [('programming_no', '=', order.production_id.programming_no)]
else: # else:
domain = [('origin', '=', order.production_id.origin)] # domain = [('origin', '=', order.production_id.origin)]
production_programming = self.env['mrp.production'].search(domain, order='name asc') # production_programming = self.env['mrp.production'].search(domain, order='name asc')
production_list = [production.name for production in production_programming] # production_list = [production.name for production in production_programming]
production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False) # production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
# technology_design = self.env['sf.technology.design'].search( # technology_design = self.env['sf.technology.design'].search(
# [('process_parameters_id', '=', order.surface_technics_parameters_id.id), # [('process_parameters_id', '=', order.surface_technics_parameters_id.id),
# ('production_id', '=', order.production_id.id)]) # ('production_id', '=', order.production_id.id)])
# if technology_design.is_auto is False: # if technology_design.is_auto is False:
# domain = [('origin', '=', order.production_id.name)] # domain = [('origin', '=', order.production_id.name)]
# else: # else:
domain = [('purchase_type', '=', 'consignment'), ('origin', '=', ','.join(production_list))] domain = [('purchase_type', '=', 'consignment'), ('origin', '=', order.production_id.name)]
purchase = self.env['purchase.order'].search(domain) purchase = self.env['purchase.order'].search(domain)
purchase_num = 0 purchase_num = 0
if not purchase: if not purchase:
order.surface_technics_purchase_count = 0 order.surface_technics_purchase_count = 0
for line in purchase.order_line: for po in purchase:
if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id: for line in po.order_line:
if line.product_qty == len(production_no_remanufacture): if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id:
purchase_num += 1 if line.product_qty == 1:
order.surface_technics_purchase_count = purchase_num purchase_num += 1
order.surface_technics_purchase_count = purchase_num
else: else:
order.surface_technics_purchase_count = 0 order.surface_technics_purchase_count = 0
def action_view_surface_technics_purchase(self): def action_view_surface_technics_purchase(self):
self.ensure_one() self.ensure_one()
if self.routing_type == '表面工艺': # if self.routing_type == '表面工艺':
if self.production_id.production_type == '自动化产线加工': # if self.production_id.production_type == '自动化产线加工':
domain = [('programming_no', '=', self.production_id.programming_no)] # domain = [('programming_no', '=', self.production_id.programming_no)]
else: # else:
domain = [('origin', '=', self.production_id.origin)] # domain = [('origin', '=', self.production_id.origin)]
production_programming = self.env['mrp.production'].search(domain, order='name asc') # production_programming = self.env['mrp.production'].search(domain, order='name asc')
production_list = [production.name for production in production_programming] # production_list = [production.name for production in production_programming]
production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False) # production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
# technology_design = self.env['sf.technology.design'].search( # technology_design = self.env['sf.technology.design'].search(
# [('process_parameters_id', '=', self.surface_technics_parameters_id.id), # [('process_parameters_id', '=', self.surface_technics_parameters_id.id),
# ('production_id', '=', self.production_id.id)]) # ('production_id', '=', self.production_id.id)])
# if technology_design.is_auto is False: # if technology_design.is_auto is False:
# domain = [('origin', '=', self.production_id.name)] # domain = [('origin', '=', self.production_id.name)]
# else: # else:
domain = [('origin', '=', ','.join(production_list)), ('purchase_type', '=', 'consignment')] domain = [('origin', '=', self.production_id.name), ('purchase_type', '=', 'consignment')]
purchase_orders = self.env['purchase.order'].search(domain) purchase_orders = self.env['purchase.order'].search(domain)
purchase_orders_id = None purchase_orders_id = None
for line in purchase_orders.order_line: for po in purchase_orders:
if line.product_id.server_product_process_parameters_id == self.surface_technics_parameters_id: for line in po.order_line:
if line.product_qty == len(production_no_remanufacture): if line.product_id.server_product_process_parameters_id == self.surface_technics_parameters_id:
purchase_orders_id = line.order_id.id if line.product_qty == 1:
purchase_orders_id = line.order_id.id
result = { result = {
"type": "ir.actions.act_window", "type": "ir.actions.act_window",
"res_model": "purchase.order", "res_model": "purchase.order",

View File

@@ -10,8 +10,14 @@ class SfProductionProcessParameter(models.Model):
@api.model @api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
if self._context.get('route_id'): if self._context.get('route_id'):
parameter = []
routing = self.env['mrp.routing.workcenter'].search([('id', '=', self._context.get('route_id'))]) routing = self.env['mrp.routing.workcenter'].search([('id', '=', self._context.get('route_id'))])
domain = [('process_id', '=', routing.surface_technics_id.id)] technology_design = self.env['sf.technology.design'].search(
[('production_id', '=', self._context.get('production_id')), ('routing_tag', '=', 'special'),
('route_id', '=', self._context.get('route_id'))])
for t in technology_design:
if t.process_parameters_id:
parameter.append(t.process_parameters_id.id)
domain = [('process_id', '=', routing.surface_technics_id.id), ('id', 'not in', parameter)]
return self._search(domain, limit=limit, access_rights_uid=name_get_uid) return self._search(domain, limit=limit, access_rights_uid=name_get_uid)
return super()._name_search(name, args, operator, limit, name_get_uid) return super()._name_search(name, args, operator, limit, name_get_uid)

View File

@@ -283,7 +283,8 @@ class StockRule(models.Model):
sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)]) sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)])
# 如果订单为空,则获取来源制造订单的销售单 # 如果订单为空,则获取来源制造订单的销售单
if not sale_order: if not sale_order:
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', production.origin)], limit=1) mrp_production = self.env['mrp.production'].sudo().search([('name', '=', production.origin)],
limit=1)
if mrp_production: if mrp_production:
sale_order = self.env['sale.order'].sudo().search([('name', '=', mrp_production.origin)]) sale_order = self.env['sale.order'].sudo().search([('name', '=', mrp_production.origin)])
else: else:
@@ -671,10 +672,14 @@ class StockPicking(models.Model):
# 创建 外协出库入单 # 创建 外协出库入单
def create_outcontract_picking(self, sorted_workorders_arr, item): def create_outcontract_picking(self, sorted_workorders_arr, item):
domain = [('origin', '=', item.name), ('name', 'ilike', 'OCOUT')]
if len(sorted_workorders_arr) > 1: if len(sorted_workorders_arr) > 1:
sorted_workorders_arr = sorted_workorders_arr[0] sorted_workorders_arr = sorted_workorders_arr[0]
stock_picking = self.env['stock.picking'].search([('origin', '=', item.name), ('name', 'ilike', 'OCOUT')]) else:
if not stock_picking or sorted_workorders_arr: domain += [
('surface_technics_parameters_id', '=', sorted_workorders_arr[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 sorted_workorders in sorted_workorders_arr:
# pick_ids = [] # pick_ids = []
if not sorted_workorders.picking_ids: if not sorted_workorders.picking_ids:

View File

@@ -368,7 +368,8 @@
attrs="{'readonly': [('id', '!=', False)]}" options="{'no_create': True}"/> attrs="{'readonly': [('id', '!=', False)]}" options="{'no_create': True}"/>
<field name="process_parameters_id" <field name="process_parameters_id"
attrs="{'readonly': [('id', '!=', False),('routing_tag', '=', 'standard')]}" attrs="{'readonly': [('id', '!=', False),('routing_tag', '=', 'standard')]}"
string="参数" context="{'route_id':route_id}" options="{'no_create': True}"/> string="参数" context="{'route_id':route_id,'production_id': production_id}"
options="{'no_create': True}"/>
<field name="panel" readonly="1"/> <field name="panel" readonly="1"/>
<field name="routing_tag" readonly="1" widget="badge" <field name="routing_tag" readonly="1" widget="badge"
decoration-success="routing_tag == 'standard'" decoration-success="routing_tag == 'standard'"

View File

@@ -49,8 +49,8 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
if ro.route_id.routing_type == '表面工艺': if ro.route_id.routing_type == '表面工艺':
domain += [('process_parameters_id', '=', ro.process_parameters_id.id)] domain += [('process_parameters_id', '=', ro.process_parameters_id.id)]
elif ro.route_id.routing_tag == 'special' and ro.is_auto is False: elif ro.route_id.routing_tag == 'special' and ro.is_auto is False:
display_name = ro.route_id.display_name # display_name = ro.route_id.display_name
domain += [('name', 'ilike', display_name)] domain += [('id', '=', ro.id)]
elif ro.panel is not False: elif ro.panel is not False:
domain += [('panel', '=', ro.panel)] domain += [('panel', '=', ro.panel)]
td_upd = self.env['sf.technology.design'].sudo().search(domain) td_upd = self.env['sf.technology.design'].sudo().search(domain)
@@ -67,7 +67,7 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
if special.process_parameters_id: if special.process_parameters_id:
domain += [('surface_technics_parameters_id', '=', special.process_parameters_id.id)] domain += [('surface_technics_parameters_id', '=', special.process_parameters_id.id)]
else: else:
domain += [('name', '=', special.route_id.name)] domain += [('technology_design_id', '=', special.id)]
workorder = self.env['mrp.workorder'].search(domain) workorder = self.env['mrp.workorder'].search(domain)
if workorder.state != 'cancel': if workorder.state != 'cancel':
workorder.write({'state': 'cancel'}) workorder.write({'state': 'cancel'})
@@ -99,7 +99,8 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
if workorder.sequence == 1: if workorder.sequence == 1:
workorder.blocked_by_workorder_ids = None workorder.blocked_by_workorder_ids = None
else: else:
workorder.blocked_by_workorder_ids = blocked_by_workorder_ids[0] if workorder.blocked_by_workorder_ids:
workorder.blocked_by_workorder_ids = blocked_by_workorder_ids[0]
productions._reset_work_order_sequence() productions._reset_work_order_sequence()
if self.production_id.product_id.categ_id.type == '成品': if self.production_id.product_id.categ_id.type == '成品':
productions._reset_subcontract_pick_purchase() productions._reset_subcontract_pick_purchase()
@@ -109,5 +110,6 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
workorders = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted( workorders = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted(
key=lambda a: a.sequence) key=lambda a: a.sequence)
if workorders[0].state in ['pending']: if workorders[0].state in ['pending']:
if workorder[0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程': if workorders[
0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程':
workorders[0].state = 'waiting' workorders[0].state = 'waiting'

View File

@@ -65,4 +65,4 @@ class ProductionTechnologyWizard(models.TransientModel):
key=lambda a: a.sequence) key=lambda a: a.sequence)
if workorder[0].state in ['pending']: if workorder[0].state in ['pending']:
if workorder[0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程': if workorder[0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程':
workorders[0].state = 'waiting' workorder[0].state = 'waiting'

View File

@@ -32,6 +32,12 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
domain += [('state', 'in', ['confirmed', 'pending_cam'])] domain += [('state', 'in', ['confirmed', 'pending_cam'])]
productions = request.env['mrp.production'].with_user( productions = request.env['mrp.production'].with_user(
request.env.ref("base.user_admin")).search(domain) request.env.ref("base.user_admin")).search(domain)
productions_technology_to_confirmed = request.env['mrp.production'].with_user(
request.env.ref("base.user_admin")).search(
[('programming_no', '=', ret['programming_no']), ('state', 'in', ['technology_to_confirmed'])])
if productions_technology_to_confirmed:
res = {'status': -2, 'message': '查询到待工艺确认的制造订单'}
return json.JSONEncoder().encode(res)
if productions: if productions:
# 拉取所有加工面的程序文件 # 拉取所有加工面的程序文件
for r in ret['processing_panel'].split(','): for r in ret['processing_panel'].split(','):

View File

@@ -250,35 +250,36 @@ class RePurchaseOrder(models.Model):
server_product_process = [] server_product_process = []
production_process = product_id_to_production_names.get( production_process = product_id_to_production_names.get(
production.product_id.id) production.product_id.id)
purchase_order = self.env['purchase.order'].search(
[('state', '=', 'draft'), ('origin', '=', production.name),
('purchase_type', '=', 'consignment')], order='name asc')
for pp in consecutive_process_parameters: for pp in consecutive_process_parameters:
server_template = self.env['product.template'].search( server_template = self.env['product.template'].search(
[('server_product_process_parameters_id', '=', pp.surface_technics_parameters_id.id), [('server_product_process_parameters_id', '=', pp.surface_technics_parameters_id.id),
('detailed_type', '=', 'service')]) ('detailed_type', '=', 'service')])
purchase_order_line = self.env['purchase.order.line'].search( if not purchase_order:
[('product_id', '=', server_template.product_variant_id.id),
('product_qty', '=', len(production_process))], limit=1, order='id desc')
if not purchase_order_line:
server_product_process.append((0, 0, { server_product_process.append((0, 0, {
'product_id': server_template.product_variant_id.id, 'product_id': server_template.product_variant_id.id,
'product_qty': len(production_process), 'product_qty': 1,
'product_uom': server_template.uom_id.id 'product_uom': server_template.uom_id.id
})) }))
else: for purchase in purchase_order:
if production.name in production_process: for po in purchase.order_line:
purchase_order = self.env['purchase.order'].search( if server_template.server_product_process_parameters_id == pp.surface_technics_parameters_id:
[('state', '=', 'draft'), ('origin', '=', ','.join(production_process)), purchase_order_line = self.env['purchase.order.line'].search(
('purchase_type', '=', 'consignment')]) [('product_id', '=', server_template.product_variant_id.id),
if not purchase_order: ('product_qty', '=', 1.0), ('id', '=', po.id)], limit=1,
server_product_process.append((0, 0, { order='id desc')
'product_id': server_template.product_variant_id.id, if not purchase_order_line and purchase not in purchase_order:
'product_qty': len(production_process), server_product_process.append((0, 0, {
'product_uom': server_template.uom_id.id 'product_id': server_template.product_variant_id.id,
})) 'product_qty': 1,
'product_uom': server_template.uom_id.id
}))
if server_product_process: if server_product_process:
self.env['purchase.order'].sudo().create({ self.env['purchase.order'].sudo().create({
'partner_id': server_template.seller_ids[0].partner_id.id, 'partner_id': server_template.seller_ids[0].partner_id.id,
'origin': ','.join(production_process), 'origin': production.name,
'state': 'draft', 'state': 'draft',
'purchase_type': 'consignment', 'purchase_type': 'consignment',
'order_line': server_product_process}) 'order_line': server_product_process})