修复报废
This commit is contained in:
@@ -126,6 +126,31 @@ class MrpProduction(models.Model):
|
||||
manual_quotation = fields.Boolean('人工编程', default=False, readonly=True)
|
||||
is_scrap = fields.Boolean('是否报废', default=False)
|
||||
is_remanufacture = fields.Boolean('是否重新制造', default=False)
|
||||
remanufacture_count = fields.Integer("重新制造订单数量", compute='_compute_remanufacture_production_ids')
|
||||
remanufacture_production_id = fields.Many2one('mrp.production', string='')
|
||||
|
||||
@api.depends('remanufacture_production_id')
|
||||
def _compute_remanufacture_production_ids(self):
|
||||
for production in self:
|
||||
if production.remanufacture_production_id:
|
||||
remanufacture_production = self.env['mrp.production'].search(
|
||||
[('id', '=', production.remanufacture_production_id.id)])
|
||||
if remanufacture_production:
|
||||
production.remanufacture_count = len(remanufacture_production)
|
||||
else:
|
||||
production.remanufacture_count = 0
|
||||
|
||||
def action_view_remanufacture_productions(self):
|
||||
self.ensure_one()
|
||||
mrp_production_ids = self.env['mrp.production'].search(
|
||||
[('id', '=', self.remanufacture_production_id.id)])
|
||||
action = {
|
||||
'res_model': 'mrp.production',
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_mode': 'form',
|
||||
'res_id': mrp_production_ids[0],
|
||||
}
|
||||
return action
|
||||
|
||||
@api.depends(
|
||||
'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state', 'tool_state',
|
||||
@@ -242,9 +267,9 @@ class MrpProduction(models.Model):
|
||||
logging.info('res=%s:' % res)
|
||||
configsettings = self.env['res.config.settings'].get_values()
|
||||
configsettings['token'] = 'ba301c9b-2216-11ef-9d97-f8b54deb92c1'
|
||||
# configsettings['sf_secret_key'] = 'rAalgsVOhDpxIWzR'
|
||||
# configsettings['sf_url'] = 'http://localhost:7069'
|
||||
# config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key'])
|
||||
configsettings['sf_secret_key'] = 'rAalgsVOhDpxIWzR'
|
||||
configsettings['sf_url'] = 'http://localhost:7069'
|
||||
config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key'])
|
||||
url = '/api/intelligent_programming/get_state'
|
||||
config_url = configsettings['sf_url'] + url
|
||||
ret = requests.post(config_url, json=res, data=None, headers=config_header)
|
||||
@@ -812,7 +837,7 @@ class MrpProduction(models.Model):
|
||||
'context': {
|
||||
'default_production_id': self.id,
|
||||
'default_reprogramming_num': cloud_programming['reprogramming_num'],
|
||||
'default_programming_state': cloud_programming['programming_state'],
|
||||
'default_programming_states': cloud_programming['programming_state'],
|
||||
'default_is_reprogramming': True if cloud_programming['programming_state'] in ['已下发'] else False
|
||||
}
|
||||
}
|
||||
@@ -959,32 +984,19 @@ class MrpProduction(models.Model):
|
||||
move_values = {'product_description_variants': '',
|
||||
'date_planned': datetime.now(),
|
||||
'date_deadline': datetime.now(),
|
||||
# 'move_dest_ids': self.env['stock.move'].search([('id', '=', move.id)]),
|
||||
'move_dest_ids': move,
|
||||
'group_id': False,
|
||||
'group_id': move.group_id,
|
||||
'route_ids': [],
|
||||
'warehouse_id': self.warehouse_id,
|
||||
'priority': 0,
|
||||
'orderpoint_id': False,
|
||||
'product_packaging_id': False}
|
||||
rule = self.env['stock.rule'].search(
|
||||
[('action', '=', 'pull'), ('procure_method', '=', 'mts_else_mto'), (
|
||||
'location_dest_id', '=', self.env['stock.location'].search([('parent_path', '=', '2/5/')]).id),
|
||||
('location_src_id', '=', self.env['stock.location'].search(
|
||||
[('barcode', '=', 'CP')]).id)])
|
||||
# origin = move._prepare_procurement_origin()
|
||||
procurement_requests.append(self.env['procurement.group'].Procurement(
|
||||
move.product_id, 1.0, move.product_uom,
|
||||
self.env['stock.location'].search([('barcode', '=', 'CP')]),
|
||||
rule and rule.name or "/",
|
||||
move.location_id, move.rule_id and move.rule_id.name or "/",
|
||||
sale_order.name, move.company_id, move_values))
|
||||
self.env['procurement.group'].run(procurement_requests,
|
||||
raise_user_error=not self.env.context.get('from_orderpoint'))
|
||||
# self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
||||
# productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
|
||||
# (
|
||||
# p.move_dest_ids.procure_method != 'make_to_order' and
|
||||
# not p.move_raw_ids and not p.workorder_ids)).action_confirm()
|
||||
productions = self.env['mrp.production'].sudo().search(
|
||||
[('origin', '=', self.origin)], order='id desc', limit=1)
|
||||
move = self.env['stock.move'].search([('origin', '=', productions.name)], order='id desc')
|
||||
@@ -1012,8 +1024,29 @@ class MrpProduction(models.Model):
|
||||
'picking_id': sfp_move.picking_id.id, 'picking_type_id': sfp_move.picking_type_id.id,
|
||||
'production_id': False})
|
||||
productions.write({'programming_no': self.programming_no, 'is_remanufacture': True})
|
||||
productions.procurement_group_id.mrp_production_ids.move_dest_ids.write(
|
||||
{'group_id': self.env['procurement.group'].search([('name', '=', sale_order.name)])})
|
||||
# productions.procurement_group_id.mrp_production_ids.move_dest_ids.write(
|
||||
# {'group_id': self.env['procurement.group'].search([('name', '=', sale_order.name)])})
|
||||
stock_picking = None
|
||||
pc_picking = self.env['stock.picking'].search(
|
||||
[('origin', '=', productions.name), ('name', 'ilike', 'WH/PC/')])
|
||||
stock_picking = pc_picking
|
||||
int_picking = self.env['stock.picking'].search(
|
||||
[('origin', '=', productions.name), ('name', 'ilike', 'WH/INT/')])
|
||||
stock_picking |= int_picking
|
||||
for pick in stock_picking:
|
||||
if pick.move_ids:
|
||||
product_type_id = pick.move_ids[0].product_id.categ_id
|
||||
if product_type_id.name == '坯料':
|
||||
location_id = self.env['stock.location'].search([('name', '=', '坯料存货区')])
|
||||
if not location_id:
|
||||
logging.info(f'没有搜索到【坯料存货区】: {location_id}')
|
||||
break
|
||||
if pick.picking_type_id.name == '内部调拨':
|
||||
if pick.location_dest_id.product_type != product_type_id:
|
||||
pick.location_dest_id = location_id.id
|
||||
elif pick.picking_type_id.name == '生产发料':
|
||||
if pick.location_id.product_type != product_type_id:
|
||||
pick.location_id = location_id.id
|
||||
scarp_process_parameter_workorder = self.env['mrp.workorder'].search(
|
||||
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', self.id),
|
||||
('is_subcontract', '=', True)])
|
||||
|
||||
@@ -184,7 +184,6 @@ class StockRule(models.Model):
|
||||
logging.info(moves)
|
||||
# Since action_confirm launch following procurement_group we should activate it.
|
||||
moves._action_confirm()
|
||||
|
||||
return True
|
||||
|
||||
@api.model
|
||||
@@ -351,17 +350,17 @@ class StockRule(models.Model):
|
||||
product_id_to_production_names)
|
||||
# # 同一个产品多个制造订单对应一个编程单和模型库
|
||||
# # 只调用一次fetchCNC,并将所有生产订单的名称作为字符串传递
|
||||
# if not production_item.programming_no:
|
||||
# production_programming = self.env['mrp.production'].search(
|
||||
# [('product_id.id', '=', production_item.product_id.id),
|
||||
# ('origin', '=', production_item.origin)],
|
||||
# limit=1, order='id asc')
|
||||
# if not production_programming.programming_no:
|
||||
# production_item.fetchCNC(
|
||||
# ', '.join(product_id_to_production_names[production_item.product_id.id]))
|
||||
# else:
|
||||
# production_item.write({'programming_no': production_programming.programming_no,
|
||||
# 'programming_state': '编程中'})
|
||||
if not production_item.programming_no:
|
||||
production_programming = self.env['mrp.production'].search(
|
||||
[('product_id.id', '=', production_item.product_id.id),
|
||||
('origin', '=', production_item.origin)],
|
||||
limit=1, order='id asc')
|
||||
if not production_programming.programming_no:
|
||||
production_item.fetchCNC(
|
||||
', '.join(product_id_to_production_names[production_item.product_id.id]))
|
||||
else:
|
||||
production_item.write({'programming_no': production_programming.programming_no,
|
||||
'programming_state': '编程中'})
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -201,6 +201,19 @@
|
||||
data-hotkey="l"/>
|
||||
</xpath>
|
||||
|
||||
<!-- <xpath expr="//header//button[@name='action_view_mo_delivery']" position="after">-->
|
||||
<!-- <button class="oe_stat_button" name="action_view_remanufacture_productions" type="object"-->
|
||||
<!-- icon="fa-wrench" attrs="{'invisible': [('remanufacture_count', '=', 0)]}"-->
|
||||
<!-- groups="mrp.group_mrp_user">-->
|
||||
<!-- <div class="o_field_widget o_stat_info">-->
|
||||
<!-- <span class="o_stat_value">-->
|
||||
<!-- <field name="remanufacture_count"/>-->
|
||||
<!-- </span>-->
|
||||
<!-- <span class="o_stat_text">新的制造</span>-->
|
||||
<!-- </div>-->
|
||||
<!-- </button>-->
|
||||
<!-- </xpath>-->
|
||||
|
||||
<xpath expr="//header//button[@name='action_toggle_is_locked']" position="replace">
|
||||
<button name="action_toggle_is_locked"
|
||||
attrs="{'invisible': ['|', ('show_lock', '=', False), ('is_locked', '=', True)]}"
|
||||
|
||||
@@ -218,7 +218,7 @@
|
||||
<xpath expr="//label[1]" position="before">
|
||||
<field name='routing_type' readonly="1"/>
|
||||
<field name='process_state' attrs='{"invisible": [("routing_type","!=","装夹预调")]}'/>
|
||||
<field name="rfid_code" force_save="1" readonly="1" cache="True"
|
||||
<field name="rfid_code" force_save="1" readonly="0" cache="True"
|
||||
attrs="{'invisible': [('rfid_code_old', '!=', False)]}"/>
|
||||
<field name="rfid_code_old" readonly="1" attrs="{'invisible': [('rfid_code_old', '=', False)]}"/>
|
||||
</xpath>
|
||||
|
||||
@@ -16,7 +16,7 @@ class ProductionWizard(models.TransientModel):
|
||||
reprogramming_num = fields.Integer('重新编程次数', default=0)
|
||||
is_reprogramming = fields.Boolean(string='申请重新编程', default=False)
|
||||
is_remanufacture = fields.Boolean(string='重新生成制造订单', default=True)
|
||||
programming_state = fields.Selection(
|
||||
programming_states = fields.Selection(
|
||||
[('待编程', '待编程'), ('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发'),
|
||||
('已下发', '已下发')],
|
||||
string='编程状态')
|
||||
@@ -27,6 +27,8 @@ class ProductionWizard(models.TransientModel):
|
||||
self.is_reprogramming = False
|
||||
|
||||
def confirm(self):
|
||||
if self.programming_state != '已下发':
|
||||
self.programming_state = '编程中'
|
||||
self.production_id.action_cancel()
|
||||
self.production_id.detection_result_ids.write({'handle_result': '已处理'})
|
||||
self.production_id.write({'state': 'cancel', 'scrap_ids': [(0, 0, {
|
||||
@@ -79,6 +81,7 @@ class ProductionWizard(models.TransientModel):
|
||||
ret['programming_list'].append(vals)
|
||||
|
||||
new_production = self.production_id.recreateManufacturing(ret)
|
||||
self.production_id.write({'remanufacture_production_id': new_production.id})
|
||||
if self.is_reprogramming is False:
|
||||
for panel in new_production.product_id.model_processing_panel.split(','):
|
||||
scrap_cnc_workorder = max(
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<form>
|
||||
<sheet>
|
||||
<field name="production_id" invisible="1"/>
|
||||
<field name="programming_state" invisible="1"/>
|
||||
<field name="programming_states" invisible="1"/>
|
||||
<div>
|
||||
重新生成制造订单
|
||||
<field name="is_remanufacture" force_save="1"/>
|
||||
@@ -17,16 +17,16 @@
|
||||
name="reprogramming_num" string=""
|
||||
readonly="1"
|
||||
style='color:red;'/>,且当前编程状态为
|
||||
<field name="programming_state" string=""
|
||||
decoration-info="programming_state == '待编程'"
|
||||
decoration-success="programming_state == '已下发'"
|
||||
decoration-warning="programming_state =='编程中'"
|
||||
decoration-danger="programming_state =='已编程'" readonly="1"/>
|
||||
<field name="programming_states" string=""
|
||||
decoration-info="programming_states == '待编程'"
|
||||
decoration-success="programming_states == '已下发'"
|
||||
decoration-warning="programming_states =='编程中'"
|
||||
decoration-danger="programming_states =='已编程'" readonly="1"/>
|
||||
</div>
|
||||
<div attrs='{"invisible": [("is_remanufacture","=",False)]}'>
|
||||
<span style='font-weight:bold;'>申请重新编程
|
||||
<field name="is_reprogramming" force_save="1"
|
||||
attrs='{"readonly": [("programming_state","not in",["已下发"])]}'/>
|
||||
attrs='{"readonly": [("programming_states","not in",["已下发"])]}'/>
|
||||
</span>
|
||||
</div>
|
||||
<footer>
|
||||
|
||||
@@ -29,21 +29,21 @@ class Sf_Mrs_Connect(http.Controller):
|
||||
[('programming_no', '=', ret['programming_no'])])
|
||||
if productions:
|
||||
# # 拉取所有加工面的程序文件
|
||||
for r in ret['processing_panel'].split(','):
|
||||
program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r)
|
||||
if os.path.exists(program_path_tmp_r):
|
||||
files_r = os.listdir(program_path_tmp_r)
|
||||
if files_r:
|
||||
for file_name in files_r:
|
||||
file_path = os.path.join(program_path_tmp_r, file_name)
|
||||
os.remove(file_path)
|
||||
download_state = request.env['sf.cnc.processing'].with_user(
|
||||
request.env.ref("base.user_admin")).download_file_tmp(
|
||||
ret['folder_name'], r)
|
||||
if download_state is False:
|
||||
res['status'] = -2
|
||||
res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no'])
|
||||
return json.JSONEncoder().encode(res)
|
||||
# for r in ret['processing_panel'].split(','):
|
||||
# program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r)
|
||||
# if os.path.exists(program_path_tmp_r):
|
||||
# files_r = os.listdir(program_path_tmp_r)
|
||||
# if files_r:
|
||||
# for file_name in files_r:
|
||||
# file_path = os.path.join(program_path_tmp_r, file_name)
|
||||
# os.remove(file_path)
|
||||
# download_state = request.env['sf.cnc.processing'].with_user(
|
||||
# request.env.ref("base.user_admin")).download_file_tmp(
|
||||
# ret['folder_name'], r)
|
||||
# if download_state is False:
|
||||
# res['status'] = -2
|
||||
# res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no'])
|
||||
# return json.JSONEncoder().encode(res)
|
||||
for production in productions:
|
||||
if not production.workorder_ids:
|
||||
production.product_id.model_processing_panel = ret['processing_panel']
|
||||
@@ -82,38 +82,38 @@ class Sf_Mrs_Connect(http.Controller):
|
||||
# if pre_workorder:
|
||||
# pre_workorder.write(
|
||||
# {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())})
|
||||
for panel in ret['processing_panel'].split(','):
|
||||
# 查询状态为进行中且工序类型为CNC加工的工单
|
||||
cnc_workorder = productions.workorder_ids.filtered(
|
||||
lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done',
|
||||
'cancel'] and ac.processing_panel == panel)
|
||||
if cnc_workorder:
|
||||
program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test',
|
||||
panel)
|
||||
program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel)
|
||||
logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel)
|
||||
files_panel = os.listdir(program_path_tmp_panel)
|
||||
if files_panel:
|
||||
for file in files_panel:
|
||||
file_extension = os.path.splitext(file)[1]
|
||||
logging.info('file_extension:%s' % file_extension)
|
||||
if file_extension.lower() == '.pdf':
|
||||
panel_file_path = os.path.join(program_path_tmp_panel, file)
|
||||
logging.info('panel_file_path:%s' % panel_file_path)
|
||||
cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())})
|
||||
pre_workorder = productions.workorder_ids.filtered(
|
||||
lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done',
|
||||
'cancel'] and ap.processing_panel == panel)
|
||||
if pre_workorder:
|
||||
pre_workorder.write(
|
||||
{'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())})
|
||||
productions.write({'programming_state': '已编程', 'work_state': '已编程'})
|
||||
cnc_program_ids = [item.id for item in productions]
|
||||
workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(
|
||||
[('production_id', 'in', cnc_program_ids)])
|
||||
if workpiece_delivery:
|
||||
workpiece_delivery.write(
|
||||
{'is_cnc_program_down': True, 'production_line_id': productions.production_line_id.id})
|
||||
# for panel in ret['processing_panel'].split(','):
|
||||
# # 查询状态为进行中且工序类型为CNC加工的工单
|
||||
# cnc_workorder = productions.workorder_ids.filtered(
|
||||
# lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done',
|
||||
# 'cancel'] and ac.processing_panel == panel)
|
||||
# if cnc_workorder:
|
||||
# program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test',
|
||||
# panel)
|
||||
# program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel)
|
||||
# logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel)
|
||||
# files_panel = os.listdir(program_path_tmp_panel)
|
||||
# if files_panel:
|
||||
# for file in files_panel:
|
||||
# file_extension = os.path.splitext(file)[1]
|
||||
# logging.info('file_extension:%s' % file_extension)
|
||||
# if file_extension.lower() == '.pdf':
|
||||
# panel_file_path = os.path.join(program_path_tmp_panel, file)
|
||||
# logging.info('panel_file_path:%s' % panel_file_path)
|
||||
# cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())})
|
||||
# pre_workorder = productions.workorder_ids.filtered(
|
||||
# lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done',
|
||||
# 'cancel'] and ap.processing_panel == panel)
|
||||
# if pre_workorder:
|
||||
# pre_workorder.write(
|
||||
# {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())})
|
||||
# productions.write({'programming_state': '已编程', 'work_state': '已编程'})
|
||||
# cnc_program_ids = [item.id for item in productions]
|
||||
# workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(
|
||||
# [('production_id', 'in', cnc_program_ids)])
|
||||
# if workpiece_delivery:
|
||||
# workpiece_delivery.write(
|
||||
# {'is_cnc_program_down': True, 'production_line_id': productions.production_line_id.id})
|
||||
return json.JSONEncoder().encode(res)
|
||||
else:
|
||||
res = {'status': 0, 'message': '该制造订单暂未开始'}
|
||||
|
||||
Reference in New Issue
Block a user