1.注释mrp_workcenter.xml文件和res.config添加不要的字段:lost_agent_id

2.制造订单新增“重新编程次数”字段,新增更新程序方法及对应的接口,优化返工且编程中的制造订单定时获取Cloud编程单状态的方法
3.优化返工向导页面及新增“重复编程次数”和“编程状态”字段
This commit is contained in:
jinling.yang
2024-07-11 17:37:35 +08:00
parent 9aca786522
commit 0fef714d61
6 changed files with 121 additions and 16 deletions

View File

@@ -8,6 +8,7 @@ _logger = logging.getLogger(__name__)
class ResBFMConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
lost_agent_id = fields.Char('22')
bfm_url = fields.Selection(
[("https://bfm.cs.jikimo.com", "开发环境(https://bfm.cs.jikimo.com)"),
("https://bfm.t.jikimo.com", "测试环境(https://bfm.t.jikimo.com)"),

View File

@@ -24,7 +24,7 @@
'views/mrp_production_addional_change.xml',
'views/mrp_routing_workcenter_view.xml',
'views/production_line_view.xml',
'views/mrp_workcenter_views.xml',
# 'views/mrp_workcenter_views.xml',
'views/mrp_workorder_view.xml',
'views/model_type_view.xml',
'views/agv_setting_views.xml',

View File

@@ -52,6 +52,7 @@ class MrpProduction(models.Model):
check_status = fields.Boolean(string='启用状态', default=False, readonly=True)
active = fields.Boolean(string='已归档', default=True)
programming_no = fields.Char('编程单号')
reprogramming_num = fields.Integer('重新编程次数', default=0)
work_state = fields.Char('业务状态')
programming_state = fields.Selection(
[('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发')], string='编程状态',
@@ -162,7 +163,11 @@ class MrpProduction(models.Model):
# 获取cloud编程单的状态
def _cron_get_programming_state(self):
try:
reproduction = self.search([('state', '=', 'rework'), ('programming_state', '=', '编程中')])
if not self:
reproduction = self.env['mrp.production'].search(
[('state', '=', 'rework'), ('programming_state', '=', '编程中')])
else:
reproduction = self
if reproduction:
programming_no = [item.programming_no for item in reproduction]
programming_no_str = ','.join(programming_no)
@@ -178,10 +183,15 @@ class MrpProduction(models.Model):
logging.info('cron_get_programming_state-ret:%s' % result)
if result['status'] == 1:
for item in result['programming_list']:
production = self.search(
[('state', '=', 'rework'), ('programming_no', '=', item['programming_no'])])
if production:
production.write({'programming_state': '已编程未下发'})
if not self:
production = self.env['mrp.production'].search(
[('state', '=', 'rework'), ('programming_no', '=', item['programming_no'])])
if production:
production.write({'programming_state': '已编程未下发' if item[
'programming_state'] == '已编程' else '编程中'})
else:
self.write({'programming_state': '已编程未下发' if item[
'programming_state'] == '已编程' else '编程中'})
else:
raise UserError(ret['message'])
except Exception as e:
@@ -742,6 +752,7 @@ class MrpProduction(models.Model):
# 返工
def button_rework(self):
self._cron_get_programming_state()
return {
'name': _('返工'),
'type': 'ir.actions.act_window',
@@ -751,7 +762,7 @@ class MrpProduction(models.Model):
'context': {
'default_production_id': self.id,
'default_product_id': self.product_id.id,
'default_is_reprogramming': True
'default_programming_state': self.programming_state
}
}
@@ -760,8 +771,87 @@ class MrpProduction(models.Model):
return True
# 更新程序
def button_update_program(self):
return True
def do_update_program(self):
program_production = self
grouped_program_ids = {k: list(g) for k, g in groupby(program_production, key=lambda x: x.programming_no)}
program_to_production_names = {}
for programming_no, program_production in grouped_program_ids.items():
program_to_production_names[programming_no] = [production.name for production in program_production]
for production in self:
if production.programming_no in program_to_production_names:
rework_workorder = production.workorder_ids.filtered(lambda m: m.state == 'rework')
if rework_workorder:
new_pancel_workorder = production.workorder_ids.filtered(
lambda m1: m1.state != 'rework' and m1.processing_panel == rework_workorder[0].processing_panel)
if not new_pancel_workorder.cnc_ids:
production.get_new_program(workorder[0].processing_panel)
rework_production = self.env['mrp.production'].search(
[('state', '=', 'rework'), ('programming_no', '=', production.programming_no)])
if rework_production:
rework_production.workorder_ids.filtered(
lambda m2: m2.state != 'rework' and m2.processing_panel == rework_workorder[
0].processing_panel and m2.routing_type == '装夹预调').write({'state': 'ready'})
rework_production.write({'state': 'progress'})
# 从cloud获取重新编程过的最新程序
def get_new_program(self, processing_panel):
try:
res = {'programming_no': self.programming_no, 'processing_panel': processing_panel}
configsettings = self.env['res.config.settings'].get_values()
config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key'])
url = '/api/intelligent_programming/get_new_program'
config_url = configsettings['sf_url'] + url
r = requests.post(config_url, json=res, data=None, headers=config_header)
r = r.json()
result = json.loads(r['result'])
if result['status'] == 1:
program_path_tmp_panel = os.path.join('/tmp', result['folder_name'], 'return', processing_panel)
if os.path.exists(program_path_tmp_panel):
files_r = os.listdir(program_path_tmp_panel)
if files_r:
for file_name in files_r:
file_path = os.path.join(program_path_tmp_panel, file_name)
os.remove(file_path)
download_state = self.env['sf.cnc.processing'].download_file_tmp(result['folder_name'],
processing_panel)
if download_state is False:
raise UserError('编程单号为%s的CNC程序文件从FTP拉取失败' % (self.programming_no))
productions = self.env['mrp.production'].search(
[('programming_no', '=', self.programming_no), ('state', 'not in', ['cancel,done'])])
if productions:
panel_workorder = productions.workorder_ids.filtered(
lambda
ac: ac.processing_panel == processing_panel and ac.routing_type == 'CNC加工' and ac.state != 'rework')
if panel_workorder:
if panel_workorder.cnc_ids:
panel_workorder.cmm_ids.sudo().unlink()
panel_workorder.cnc_ids.sudo().unlink()
self.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan(
productions)
# program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test',
# 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]
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)
panel_workorder.write(
{'cnc_ids': panel_workorder.cnc_ids.sudo()._json_cnc_processing(processing_panel, ret),
'cmm_ids': panel_workorder.cmm_ids.sudo()._json_cmm_program(processing_panel, ret),
'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())})
pre_workorder = productions.workorder_ids.filtered(lambda
ap: ap.routing_type == '装夹预调' and ap.processing_panel == processing_panel and ap.state != 'rework')
if pre_workorder:
pre_workorder.write(
{'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())})
else:
raise UserError(result['message'])
except Exception as e:
logging.info('get_new_program error:%s' % e)
raise UserError("从cloud获取最新程序失败,请联系管理员")
class sf_detection_result(models.Model):

View File

@@ -7,9 +7,9 @@
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_tree_view"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='do_unreserve']" position="after">
<!-- <button name="do_unreserve" type="object" string="更新程序"/>-->
</xpath>
<!-- <xpath expr="//button[@name='do_unreserve']" position="after">-->
<!-- <button name="do_update_program" type="object" string="更新程序"/>-->
<!-- </xpath>-->
<xpath expr="//field[@name='product_id']" position="replace"/>
<xpath expr="//field[@name='product_qty']" position="replace"/>
<xpath expr="//field[@name='product_uom_id']" position="replace"/>
@@ -119,8 +119,6 @@
<button name="button_scrap" invisible="1"/>
<button name="button_rework" string="返工" type="object" groups="sf_base.group_sf_mrp_user"/>
<button name="button_scrap_new" string="报废" type="object" groups="sf_base.group_sf_mrp_user"/>
<button name="button_update_program" string="更新程序" type="object"
groups="sf_base.group_sf_mrp_user"/>
</xpath>
<xpath expr="(//header//button[@name='button_mark_done'])[3]" position="replace">
<button name="button_mark_done" attrs="{'invisible': [

View File

@@ -24,6 +24,9 @@ class ReworkWizard(models.TransientModel):
# 根据工单的加工面来显示
processing_panel_id = fields.Many2one('sf.processing.panel', string="加工面")
is_reprogramming = fields.Boolean(string='申请重新编程', default=False)
reprogramming_num = fields.Integer('重新编程次数', default=0)
programming_state = fields.Selection(
[('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发')], string='编程状态')
def confirm(self):
if self.is_reprogramming is True:
@@ -44,7 +47,8 @@ class ReworkWizard(models.TransientModel):
self.production_id, route, False))
if workorders_values:
self.production_id.write(
{'workorder_ids': workorders_values, 'programming_state': '编程中', 'work_state': '编程中'})
{'workorder_ids': workorders_values, 'programming_state': '编程中', 'work_state': '编程中',
'reprogramming_num': self.production_id.reprogramming_num + 1})
self.production_id._reset_work_order_sequence()
self.production_id.update_programming_state()
else:

View File

@@ -11,8 +11,20 @@
<field name="product_id" invisible="True"/>
<group>
<field name="processing_panel_id" options="{'no_create': True}"/>
</group>
<div>
注意*: 该制造订单的产品已重复编程过<field name="reprogramming_num" string=""
readonly="1"
style='color:red;'/>次,且当前编程状态为
<field name="programming_state" string=""
decoration-success="programming_state == '已编程'"
decoration-warning="programming_state =='编程中'"
decoration-danger="programming_state =='已编程未下发'" readonly="1"/>
</div>
<group>
<field name="is_reprogramming"
attrs='{"invisible": [("is_reprogramming","=",False)],"readonly": [("is_reprogramming","=",True)]}'/>
attrs='{"invisible": [("is_reprogramming","=",False)],"readonly": [("programming_state","in",["编程中","已编程未下发时"])]}'/>
<field name="rework_reason"
attrs='{"invisible": [("is_reprogramming","=",True)],"required": [("is_reprogramming","=",False)]}'/>
<field name="detailed_reason"