Merge branch 'develop' of https://e.coding.net/jikimo-hn/jikimo_sfs/jikimo_sf into feature/产品的权限优化

# Conflicts:
#	sf_dlm_management/views/product_template_management_view.xml
#	sf_sale/models/quick_easy_order.py
#	sf_sale/models/sale_order.py
#	sf_sale/views/purchase_order_view.xml
This commit is contained in:
jinling.yang
2024-02-22 09:35:18 +08:00
194 changed files with 9912 additions and 3459 deletions

View File

@@ -1,6 +1,12 @@
# -*- coding: utf-8 -*-
import base64
import logging
import re
import requests
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.addons.sf_base.commons.common import Common
from odoo.tools import float_compare, float_round, float_is_zero, format_datetime
class MrpProduction(models.Model):
@@ -12,11 +18,80 @@ class MrpProduction(models.Model):
maintenance_count = fields.Integer(compute='_compute_maintenance_count', string="Number of maintenance requests")
request_ids = fields.One2many('maintenance.request', 'production_id')
model_file = fields.Binary('模型文件', related='product_id.model_file')
schedule_state = fields.Selection([('未排', '未排'), ('已排', '已排')],
schedule_state = fields.Selection([('未排', '未排'), ('已排', '已排'), ('已完成', '已完成')],
string='排程状态', default='未排')
# state = fields.Selection(selection_add=[
# ('pending_scheduling', '待排程'),
# ('pending_processing', '待加工'),
# ('completed', '已完工')
# ])
state = fields.Selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
('progress', '待排程'),
('pending_processing', '待加工'),
('completed', '已完工'),
('to_close', 'To Close'),
('done', 'Done'),
('cancel', 'Cancelled')], string='State',
compute='_compute_state', copy=False, index=True, readonly=True,
store=True, tracking=True,
help=" * Draft: The MO is not confirmed yet.\n"
" * Confirmed: The MO is confirmed, the stock rules and the reordering of the components are trigerred.\n"
" * In Progress: The production has started (on the MO or on the WO).\n"
" * To Close: The production is done, the MO has to be closed.\n"
" * Done: The MO is closed, the stock moves are posted. \n"
" * Cancelled: The MO has been cancelled, can't be confirmed anymore.")
check_status = fields.Boolean(string='启用状态', default=False, readonly=True)
active = fields.Boolean(string='已归档', default=True)
programming_no = fields.Char('编程单号')
work_state = fields.Char('业务状态')
programming_state = fields.Char('编程状态')
glb_file = fields.Binary("glb模型文件")
production_line_id = fields.Many2one('sf.production.line', string='生产线')
plan_start_processing_time = fields.Datetime('计划开始加工时间')
@api.depends(
'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state',
'workorder_ids.state', 'product_qty', 'qty_producing', 'schedule_state')
def _compute_state(self):
for production in self:
if not production.state or not production.product_uom_id:
production.state = 'draft'
elif production.state == 'cancel' or (production.move_finished_ids and all(
move.state == 'cancel' for move in production.move_finished_ids)):
production.state = 'cancel'
elif (
production.state == 'done'
or (production.move_raw_ids and all(
move.state in ('cancel', 'done') for move in production.move_raw_ids))
and all(move.state in ('cancel', 'done') for move in production.move_finished_ids)
):
production.state = 'done'
elif production.workorder_ids and all(
wo_state in ('done', 'cancel') for wo_state in production.workorder_ids.mapped('state')):
production.state = 'to_close'
elif not production.workorder_ids and float_compare(production.qty_producing, production.product_qty,
precision_rounding=production.product_uom_id.rounding) >= 0:
production.state = 'to_close'
elif any(wo_state in ('progress', 'done') for wo_state in production.workorder_ids.mapped('state')):
production.state = 'progress'
elif production.product_uom_id and not float_is_zero(production.qty_producing,
precision_rounding=production.product_uom_id.rounding):
production.state = 'progress'
elif any(not float_is_zero(move.quantity_done,
precision_rounding=move.product_uom.rounding or move.product_id.uom_id.rounding)
for move in production.move_raw_ids):
production.state = 'progress'
# 新添加的状态逻辑
if production.state == 'progress' and production.schedule_state == '已排':
production.state = 'pending_processing'
elif production.state == 'progress' and production.schedule_state == '已完成':
production.state = 'completed'
def action_check(self):
"""
@@ -47,6 +122,47 @@ class MrpProduction(models.Model):
for production in self:
production.maintenance_count = len(production.request_ids)
# cnc程序获取
def fetchCNC(self):
cnc = self.env['mrp.production'].search([('id', '=', self.id)])
try:
res = {'model_code': '' if not cnc.product_id.model_code else cnc.product_id.model_code,
'production_no': cnc.name,
'machine_tool_code': "",
'material_code': self.env['sf.production.materials'].search(
[('id', '=', cnc.product_id.materials_id.id)]).materials_no,
'material_type_code': self.env['sf.materials.model'].search(
[('id', '=', cnc.product_id.materials_type_id.id)]).materials_no,
'machining_processing_panel': cnc.product_id.model_processing_panel,
'machining_precision': cnc.product_id.model_machining_precision,
'embryo_long': cnc.product_id.bom_ids.bom_line_ids.product_id.length,
'embryo_height': cnc.product_id.bom_ids.bom_line_ids.product_id.height,
'embryo_width': cnc.product_id.bom_ids.bom_line_ids.product_id.width,
'order_no': cnc.origin,
'model_order_no': cnc.product_id.default_code.rsplit(' -', 1)[0],
'user': cnc.env.user.name,
'model_file': '' if not cnc.product_id.model_file else base64.b64encode(
cnc.product_id.model_file).decode('utf-8')
}
logging.info('res:%s' % res)
configsettings = self.env['res.config.settings'].get_values()
config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key'])
url = '/api/intelligent_programming/create'
config_url = configsettings['sf_url'] + url
res['token'] = configsettings['token']
# res_str = json.dumps(res)
ret = requests.post(config_url, json={}, data=res, headers=config_header)
ret = ret.json()
logging.info('fetchCNC-ret:%s' % ret)
if ret['status'] == 1:
self.write(
{'programming_no': ret['programming_no'], 'programming_state': '编程中', 'work_state': '编程中'})
else:
raise UserError(ret['message'])
except Exception as e:
logging.info('fetchCNC error:%s' % e)
raise UserError("cnc程序获取编程单失败,请联系管理员")
# 维修模块按钮
def button_maintenance_req(self):
self.ensure_one()
@@ -134,6 +250,7 @@ class MrpProduction(models.Model):
'state': 'pending',
}]
if production.product_id.categ_id.type == '成品':
production.fetchCNC()
# 根据加工面板的面数及对应的工序模板生成工单
i = 0
processing_panel_len = len(production.product_id.model_processing_panel.split(','))
@@ -144,9 +261,6 @@ class MrpProduction(models.Model):
)
i += 1
for route in product_routing_workcenter:
if i == 1 and route.routing_type == '获取CNC加工程序':
workorders_values.append(
self.env['mrp.workorder'].json_workorder_str('', production, route))
if route.is_repeat is True:
workorders_values.append(
self.env['mrp.workorder'].json_workorder_str(k, production, route))
@@ -339,10 +453,10 @@ class MrpProduction(models.Model):
for route in routingworkcenter:
if route.routing_type == '后置三元质量检测':
workorders_values.append(
self.env['mrp.workorder'].json_workorder_str1(k, production, route)
)
# if route.routing_type == '后置三元质量检测':
# workorders_values.append(
# self.env['mrp.workorder'].json_workorder_str1(k, production, route)
# )
if route.routing_type == 'CNC加工':
workorders_values.append(
self.env['mrp.workorder'].json_workorder_str1(k, production, route))
@@ -364,12 +478,104 @@ class MrpProduction(models.Model):
for work in rec.workorder_ids:
work.sequence = current_sequence
current_sequence += 1
if work.name == '获取CNC加工程序':
work.button_start()
work.fetchCNC()
# if work.name == '获取CNC加工程序':
# work.button_start()
# #work.fetchCNC()
# work.button_finish()
# 创建工单并进行排序
def _create_workorder(self):
self._create_workorder3()
self._reset_work_order_sequence()
return True
# 修改标记已完成方法
def button_mark_done1(self):
self._button_mark_done_sanity_checks()
if not self.env.context.get('button_mark_done_production_ids'):
self = self.with_context(button_mark_done_production_ids=self.ids)
res = self._pre_button_mark_done()
if res is not True:
return res
if self.env.context.get('mo_ids_to_backorder'):
productions_to_backorder = self.browse(self.env.context['mo_ids_to_backorder'])
productions_not_to_backorder = self - productions_to_backorder
else:
productions_not_to_backorder = self
productions_to_backorder = self.env['mrp.production']
backorders = productions_to_backorder and productions_to_backorder._split_productions()
backorders = backorders - productions_to_backorder
productions_not_to_backorder._post_inventory(cancel_backorder=True)
productions_to_backorder._post_inventory(cancel_backorder=True)
# if completed products make other confirmed/partially_available moves available, assign them
done_move_finished_ids = (
productions_to_backorder.move_finished_ids | productions_not_to_backorder.move_finished_ids).filtered(
lambda m: m.state == 'done')
done_move_finished_ids._trigger_assign()
# Moves without quantity done are not posted => set them as done instead of canceling. In
# case the user edits the MO later on and sets some consumed quantity on those, we do not
# want the move lines to be canceled.
(productions_not_to_backorder.move_raw_ids | productions_not_to_backorder.move_finished_ids).filtered(
lambda x: x.state not in ('done', 'cancel')).write({
'state': 'done',
'product_uom_qty': 0.0,
})
for production in self:
production.write({
'date_finished': fields.Datetime.now(),
'product_qty': production.qty_produced,
'priority': '0',
'is_locked': True,
'state': 'done',
})
for workorder in self.workorder_ids.filtered(lambda w: w.state not in ('done', 'cancel')):
workorder.duration_expected = workorder._get_duration_expected()
if not backorders:
if self.env.context.get('from_workorder'):
return {
'type': 'ir.actions.act_window',
'res_model': 'mrp.production',
'views': [[self.env.ref('mrp.mrp_production_form_view').id, 'form']],
'res_id': self.id,
'target': 'main',
}
if self.user_has_groups(
'mrp.group_mrp_reception_report') and self.picking_type_id.auto_show_reception_report:
lines = self.move_finished_ids.filtered(lambda
m: m.product_id.type == 'product' and m.state != 'cancel' and m.quantity_done and not m.move_dest_ids)
if lines:
if any(mo.show_allocation for mo in self):
action = self.action_view_reception_report()
return action
return True
context = self.env.context.copy()
context = {k: v for k, v in context.items() if not k.startswith('default_')}
for k, v in context.items():
if k.startswith('skip_'):
context[k] = False
action = {
'res_model': 'mrp.production',
'type': 'ir.actions.act_window',
'context': dict(context, mo_ids_to_backorder=None, button_mark_done_production_ids=None)
}
if len(backorders) == 1:
action.update({
'view_mode': 'form',
'res_id': backorders[0].id,
})
else:
action.update({
'name': _("Backorder MO"),
'domain': [('id', 'in', backorders.ids)],
'view_mode': 'tree,form',
})
return action

View File

@@ -1,16 +1,17 @@
import logging
from odoo import fields, models
from odoo import fields, models, api
from odoo.exceptions import UserError
class ResMrpRoutingWorkcenter(models.Model):
_inherit = 'mrp.routing.workcenter'
routing_type = fields.Selection([
('获取CNC加工程序', '获取CNC加工程序'),
('装夹', '装夹'),
('前置三元定位检测', '前置三元定位检测'),
# ('获取CNC加工程序', '获取CNC加工程序'),
('装夹预调', '装夹预调'),
# ('前置三元定位检测', '前置三元定位检测'),
('CNC加工', 'CNC加工'),
('后置三元质量检测', '后置三元质量检测'),
# ('后置三元质量检测', '后置三元质量检测'),
('解除装夹', '解除装夹'),
('切割', '切割'),
('表面工艺', '表面工艺')
@@ -21,13 +22,17 @@ class ResMrpRoutingWorkcenter(models.Model):
bom_id = fields.Many2one('mrp.bom', required=False)
surface_technics_id = fields.Many2one('sf.production.process', string="表面工艺")
def generate_code(self):
return self.env['ir.sequence'].next_by_code('mrp.routing.workcenter')
code = fields.Char('编码', default=generate_code)
# 获得当前登陆者公司
def get_company_id(self):
self.company_id = self.env.user.company_id.id
company_id = fields.Many2one('res.company', compute="get_company_id", related=False)
# 排产的时候, 根据坯料的长宽高比对一下机床的最大加工尺寸.不符合就不要分配给这个加工中心(机床).
# 工单对应的工作中心,根据工序中的工作中心去匹配,
# 如果只配置了一个工作中心,则默认采用该工作中心;

View File

@@ -22,7 +22,7 @@ class ResWorkcenter(models.Model):
equipment_status = fields.Selection(
[("正常", "正常"), ("故障", "故障"), ("不可用", "不可用")],
[("正常", "正常"), ("故障停机", "故障停机"), ("计划维保", "计划维保"),("空闲", "空闲"),("封存(报废)", "封存(报废)")],
string="设备状态", related='equipment_id.state')
# @api.depends('equipment_id')

View File

@@ -31,11 +31,11 @@ class ResMrpWorkOrder(models.Model):
processing_panel = fields.Char('加工面')
sequence = fields.Integer(string='工序')
routing_type = fields.Selection([
('获取CNC加工程序', '获取CNC加工程序'),
('装夹', '装夹'),
('前置三元定位检测', '前置三元定位检测'),
# ('获取CNC加工程序', '获取CNC加工程序'),
('装夹预调', '装夹预调'),
# ('前置三元定位检测', '前置三元定位检测'),
('CNC加工', 'CNC加工'),
('后置三元质量检测', '后置三元质量检测'),
# ('后置三元质量检测', '后置三元质量检测'),
('解除装夹', '解除装夹'),
('切割', '切割'), ('表面工艺', '表面工艺')
], string="工序类型")
@@ -122,22 +122,28 @@ class ResMrpWorkOrder(models.Model):
chuck_type_id = fields.Char(string="卡盘类型")
chuck_model_id = fields.Char(string="卡盘型号")
tray_serial_number = fields.Char(string="托盘序列号")
tray_name = fields.Char(string="托盘名称")
tray_product_id = fields.Many2one('product.product', string="托盘名称")
tray_brand_id = fields.Many2one('sf.machine.brand', string="托盘品牌")
tray_type_id = fields.Char(string="托盘类型")
tray_model_id = fields.Char(string="托盘型号")
tray_type_id = fields.Many2one('sf.fixture.material', string="托盘类型")
tray_model_id = fields.Many2one('sf.fixture.model', string="托盘型号")
total_wight = fields.Float(string="总重量")
maximum_carrying_weight = fields.Char(string="最大承载重量[kg]")
maximum_clamping_force = fields.Char(string="最大夹持力[n]")
production_line = fields.Char(string="生产线")
preset_program_information = fields.Char(string="预调程序信息")
workpiece_delivery_ids = fields.One2many('sf.workpiece.delivery', 'workorder_id', '工件配送')
is_delivery = fields.Boolean('是否配送完成', default=False)
rfid_code = fields.Char('RFID')
@api.onchange('is_ok')
def _onchange_inspection_user_id(self):
"""
检测is_ok(是否合格)被修改的话就将当前用户赋值给inspection_user_id
"""
self.inspection_user_id = self.env.user.id
if not self.inspection_user_id:
self.inspection_user_id = self.env.user.id
else:
self.inspection_user_id = False
@api.onchange('functional_fixture_id')
def _onchange_functional_fixture_id(self):
@@ -192,30 +198,41 @@ class ResMrpWorkOrder(models.Model):
work = workorder.production_id.workorder_ids
work.compensation_value_x = eval(self.material_center_point)[0]
work.compensation_value_y = eval(self.material_center_point)[1]
workorder.button_finish()
except:
raise UserError("参数计算有误")
def button_workpiece_delivery(self):
if self.routing_type == '装夹预调':
for item in self.workpiece_delivery_ids:
if not item.feeder_station_start:
raise UserError('【工件配送】明细中请输入起点接驳站')
# if not item.workpiece_code:
# raise UserError('请对【同运工件】进行扫描')
else:
item.write({'task_delivery_time': fields.Datetime.now(), 'status': '待配送'})
# 拼接工单对象属性值
def json_workorder_str(self, k, production, route):
# 计算预计时长duration_expected
if route.routing_type == '切割':
duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
[('name', '=', '切割')]).time_cycle
elif route.routing_type == '获取CNC加工程序':
# elif route.routing_type == '获取CNC加工程序':
# duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
# [('name', '=', '获取CNC加工程序')]).time_cycle
elif route.routing_type == '装夹预调':
duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
[('name', '=', '获取CNC加工程序')]).time_cycle
elif route.routing_type == '工件装夹':
duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
[('name', '=', '工件装夹')]).time_cycle
elif route.routing_type == '前置三元定位检测':
duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
[('name', '=', '前置三元定位检测')]).time_cycle
[('name', '=', '装夹预调')]).time_cycle
# elif route.routing_type == '前置三元定位检测':
# duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
# [('name', '=', '前置三元定位检测')]).time_cycle
elif route.routing_type == 'CNC加工':
duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
[('name', '=', 'CNC加工')]).time_cycle
elif route.routing_type == '后置三元质量检测':
duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
[('name', '=', '后置三元质量检测')]).time_cycle
# elif route.routing_type == '后置三元质量检测':
# duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
# [('name', '=', '后置三元质量检测')]).time_cycle
elif route.routing_type == '解除装夹':
duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
[('name', '=', '解除装夹')]).time_cycle
@@ -229,7 +246,7 @@ class ResMrpWorkOrder(models.Model):
'processing_panel': k,
'quality_point_ids': route.route_workcenter_id.quality_point_ids,
'routing_type': route.routing_type,
'work_state': '' if not route.routing_type == '获取CNC加工程序' else '待发起',
'work_state': '待发起',
'workcenter_id': self.env['mrp.routing.workcenter'].get_workcenter(route.workcenter_ids.ids,
route.routing_type,
production.product_id),
@@ -237,7 +254,9 @@ class ResMrpWorkOrder(models.Model):
'date_planned_finished': False,
'duration_expected': duration_expected,
'duration': 0,
'workpiece_delivery_ids': False if not route.routing_type == '装夹预调' else self.env[
'sf.workpiece.delivery'].create(
{'production_id': production.id})
}]
return workorders_values_str
@@ -447,7 +466,7 @@ class ResMrpWorkOrder(models.Model):
'embryo_height': cnc.product_id.bom_ids.bom_line_ids.product_id.height,
'embryo_width': cnc.product_id.bom_ids.bom_line_ids.product_id.width,
'order_no': cnc.production_id.origin,
'model_order_no': cnc.product_id.default_code.rsplit('-', 1)[0],
'model_order_no': cnc.product_id.default_code.rsplit(' -', 1)[0],
'user': self.env.user.name,
'model_file': '' if not cnc.product_id.model_file else base64.b64encode(
cnc.product_id.model_file).decode('utf-8')
@@ -492,7 +511,7 @@ class ResMrpWorkOrder(models.Model):
# 重写工单开始按钮方法
def button_start(self):
if self.routing_type == '装夹' and self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name:
if self.routing_type == '装夹预调' and self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name:
self.pro_code = self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name
# 外协出库单,从“正在等待”变为“就绪”状态
if self.is_subcontract is True:
@@ -548,6 +567,9 @@ class ResMrpWorkOrder(models.Model):
raise UserError(_('请先完成上一步工单'))
def button_finish(self):
if self.routing_type == '装夹预调':
if not self.material_center_point and self.X_deviation_angle > 0:
raise UserError("请对前置三元检测定位参数进行计算定位")
if self.picking_out_id:
picking_out = self.env['stock.picking'].search([('id', '=', self.picking_out_id.id)])
if picking_out.workorder_out_id:
@@ -571,6 +593,15 @@ class ResMrpWorkOrder(models.Model):
'order_line': order_line_ids,
})
super().button_finish()
is_production_id = True
for workorder in self.production_id.workorder_ids:
if workorder.state != 'done':
is_production_id = False
if is_production_id == True and self.name == '解除装夹':
for move_raw_id in self.production_id.move_raw_ids:
move_raw_id.quantity_done = move_raw_id.product_uom_qty
self.production_id.button_mark_done1()
# self.production_id.state = 'done'
class CNCprocessing(models.Model):
@@ -581,6 +612,7 @@ class CNCprocessing(models.Model):
cnc_id = fields.Many2one('ir.attachment')
sequence_number = fields.Char('序号')
program_name = fields.Char('程序名')
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型')
cutting_tool_name = fields.Char('刀具名称')
cutting_tool_no = fields.Char('刀号')
processing_type = fields.Char('加工类型')
@@ -592,6 +624,7 @@ class CNCprocessing(models.Model):
estimated_processing_time = fields.Char('预计加工时间')
remark = fields.Text('备注')
workorder_id = fields.Many2one('mrp.workorder', string="工单")
production_id = fields.Many2one('mrp.production', string="制造订单")
button_state = fields.Boolean(string='是否已经下发')
# mrs下发编程单创建CNC加工
@@ -601,6 +634,8 @@ class CNCprocessing(models.Model):
workorder = self.env['mrp.workorder'].search([('production_id.name', '=', ret['production_order_no']),
('processing_panel', '=', obj['processing_panel']),
('routing_type', '=', 'CNC加工')])
logging.info('workorder:%s' % workorder)
logging.info('obj:%s' % obj)
cnc_processing = self.env['sf.cnc.processing'].create({
'workorder_id': workorder.id,
'sequence_number': obj['sequence_number'],
@@ -616,19 +651,19 @@ class CNCprocessing(models.Model):
'estimated_processing_time': obj['estimated_processing_time'],
'remark': obj['remark']
})
self.get_cnc_processing_file(ret['folder_name'], cnc_processing, workorder.processing_panel)
cnc_workorder.state = 'done'
cnc_processing.get_cnc_processing_file(ret['folder_name'], cnc_processing, workorder.processing_panel)
# cnc_workorder.state = 'done'
cnc_workorder.work_state = '已编程'
cnc_workorder.programming_state = '已编程'
cnc_workorder.time_ids.date_end = datetime.now()
cnc_workorder.button_finish()
# cnc_workorder.time_ids.date_end = datetime.now()
# cnc_workorder.button_finish()
# 根据程序名和加工面匹配到ftp里对应的Nc程序名
def get_cnc_processing_file(self, folder_name, cnc_processing, processing_panel):
logging.info('folder_name:%s' % folder_name)
serverdir = os.path.join('/tmp', folder_name, 'return', processing_panel)
logging.info('serverdir:%s' % serverdir)
for root, files in os.walk(serverdir):
for root, dirs, files in os.walk(serverdir):
for f in files:
logging.info('f:%s' % f)
if os.path.splitext(f)[1] == ".pdf":
@@ -663,6 +698,7 @@ class CNCprocessing(models.Model):
ftp = FtpController(str(ftp_resconfig['ftp_host']), int(ftp_resconfig['ftp_port']), ftp_resconfig['ftp_user'],
ftp_resconfig['ftp_password'])
download_state = ftp.download_file_tree(remotepath, serverdir)
logging.info('download_state:%s' % download_state)
return download_state
# 将nc文件存到attach的datas里
@@ -703,51 +739,107 @@ class SfWorkOrderBarcodes(models.Model):
_name = "mrp.workorder"
_inherit = ["mrp.workorder", "barcodes.barcode_events_mixin"]
# def on_barcode_scanned(self, barcode):
# workorder = self.env['mrp.workorder'].browse(self.ids)
# if "*" not in barcode:
# if self.routing_type == '装夹':
# tray_code = self.env['sf.tray'].search([('code', '=', barcode)])
# self.tray_code = tray_code.code
# self.tray_id = workorder.gettray_auto(barcode)
# elif self.routing_type == '前置三元定位检测':
# print('我是前置三元检测')
# logging.info('我是前置三元检测')
# elif self.routing_type == 'CNC加工':
# if barcode == 'UP-ALL':
# print("我是一键合并下发")
# logging.info('我是一键合并下发')
# self.up_merge_all()
# else:
# print('CNC加工')
# # print(barcode)
# # a = self.env['sf.tray'].search([('code', '=', barcode)])
# # print(a)
# # # workorder_obj = self.env['mrp.workorder'].search([('tray_code', '=', barcode)], limit=1)
# # workorder_obj = self.env['mrp.workorder'].search([('tray_code', '=', barcode)])
# # e = workorder_obj.id
# # print(workorder_obj)
# # action = {
# # 'name': '工单',
# # 'type': 'ir.actions.act_window',
# # # 'view_type': 'form',
# # 'view_mode': 'form',
# # 'res_model': 'mrp.workorder',
# # 'view_id': self.env.ref('mrp.mrp_production_workorder_form_view_inherit').id,
# # # 'res_id': workorder_obj.id,
# # 'res_id': 1023,
# # 'target': 'current',
# # # 'context': self.env.context,
# # # 'flags': {'initial_mode': 'edit'},
# # }
# # return action
#
# elif self.routing_type == '后置三元质量检测':
# print('后置三元检测')
# elif self.routing_type == '解除装夹':
# print("我是解除装夹")
# else:
# pass
#
# else:
# self.pro_code_ok = workorder.pro_code_is_ok(barcode)
def on_barcode_scanned(self, barcode):
workorder = self.env['mrp.workorder'].browse(self.ids)
# workorder = self.env['mrp.workorder'].search(
# [('routing_type', '=', '装夹预调'), ('production_id', '=', self.production_id.id)])
if workorder:
if workorder.routing_type == '装夹预调':
stock_move_line = self.env['stock.move.line'].search([('lot_name', '=', barcode)])
if stock_move_line.product_id.categ_type == '夹具':
workorder.write({
'tray_serial_number': stock_move_line.lot_name,
'tray_product_id': stock_move_line.product_id.id,
'tray_brand_id': stock_move_line.product_id.brand_id.id,
'tray_type_id': stock_move_line.product_id.fixture_material_id.id,
'tray_model_id': stock_move_line.product_id.fixture_model_id.id
})
workorder.button_start()
# return {
# 'type': 'ir.actions.act_window',
# 'res_model': 'mrp.workorder',
# 'view_mode': 'form',
# 'domain': [('id', 'in', workorder.id)],
# 'target': 'current'
# }
else:
embryo_stock_lot = self.env['stock.lot'].search([('name', '=', barcode)])
if embryo_stock_lot:
embryo_stock_move_line = self.env['stock.move.line'].search(
[('product_id', '=', embryo_stock_lot.product_id.id),
('reference', '=', workorder.production_id.name),
('lot_id', '=', embryo_stock_lot.id),
('product_category_name', '=', '坯料')])
if embryo_stock_move_line:
bom_production = self.env['mrp.production'].search(
[('product_id', '=', embryo_stock_lot.product_id.id),
('origin', '=', workorder.production_id.name)], limit=1, order='id asc')
workpiece_delivery = self.env['sf.workpiece.delivery'].search(
[('workorder_id', '=', workorder.id)], limit=1, order='id asc')
if workpiece_delivery:
embryo_workpiece_code = workpiece_delivery.workpiece_code
if bom_production:
if workpiece_delivery.workpiece_code and bom_production.name not in \
workpiece_delivery.workpiece_code:
embryo_workpiece_code = workpiece_delivery.workpiece_code + ',' + \
bom_production.name
if not workpiece_delivery.workpiece_code:
embryo_workpiece_code = bom_production.name
workpiece_delivery.write({'workpiece_code': embryo_workpiece_code})
else:
raise UserError('工件生产线不一致,请重新确认')
class WorkPieceDelivery(models.Model):
_name = "sf.workpiece.delivery"
_description = '工件配送'
workorder_id = fields.Many2one('mrp.workorder', string='工单', readonly=True)
production_id = fields.Many2one('mrp.production', string='制造订单', readonly=True)
production_line_id = fields.Many2one('sf.production.line', compute='_compute_production_line_id',
string='目的生产线', readonly=True,
store=True)
plan_start_processing_time = fields.Datetime('计划开始加工时间', readonly=True)
workpiece_code = fields.Char('同运工件编码')
feeder_station_start = fields.Char('起点接驳站')
feeder_station_destination = fields.Char('目的接驳站')
task_delivery_time = fields.Datetime('任务下发时间')
task_completion_time = fields.Datetime('任务完成时间')
delivery_duration = fields.Float('配送时长', compute='_compute_delivery_duration')
status = fields.Selection(
[('待下发', '待下发'), ('待配送', '待配送'), ('已配送', '已配送')], string='状态',
default='待下发')
# 工件配送
def button_delivery(self):
if self.status == '待下发':
return {
'name': _('确认'),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'sf.workpiece.delivery.wizard',
'target': 'new',
'context': {
'default_delivery_id': self.id,
}}
else:
raise UserError('状态为【待下发】的工件记录可进行配送')
# 配送至avg小车
def _delivery_avg(self):
self.write({'task_delivery_time': fields.Datetime.now(), 'status': '待配送'})
@api.depends('production_id.production_line_id')
def _compute_production_line_id(self):
if self.production_id.production_line_id:
self.production_line_id = self.production_id.production_line_id.id
self.plan_start_processing_time = self.production_id.plan_start_processing_time
@api.depends('task_delivery_time', 'task_completion_time')
def _compute_delivery_duration(self):
for obj in self:
if obj.task_delivery_time and obj.task_completion_time:
obj.delivery_duration = round(
(obj.task_completion_time - obj.task_delivery_time).total_seconds() / 60.0, 2)
else:
obj.delivery_duration = 0.0

View File

@@ -62,7 +62,6 @@ class ResProductMo(models.Model):
tool_thickness = fields.Float('厚度(mm)')
tool_weight = fields.Float('重量(kg)')
tool_hardness = fields.Integer('硬度(hrc)')
coating_material = fields.Char('涂层材质')
# 整体式刀具特有字段
cutting_tool_total_length = fields.Float('总长度(mm)', digits=(6, 1))
@@ -97,8 +96,8 @@ class ResProductMo(models.Model):
handle_type_id = fields.Many2one('maintenance.equipment.image', '柄部类型', domain=[('type', '=', '柄部类型')])
cutting_direction_ids = fields.Many2many('maintenance.equipment.image', 'rel_cutting_product_template',
'走刀方向', domain=[('type', '=', '走刀方向')])
suitable_coolant_ids = fields.Many2many('maintenance.equipment.image', 'rel_coolant_product_template',
'适合冷却', domain=[('type', '=', '冷却')])
suitable_coolant_ids = fields.Many2many('maintenance.equipment.image', 'rel_coolants_product_template',
'适合冷却方式', domain=[('type', '=', '冷却方式')])
compaction_way_id = fields.Many2one('maintenance.equipment.image',
'压紧方式', domain=[('type', '=', '压紧方式')])
@@ -202,8 +201,6 @@ class ResProductMo(models.Model):
self.feed_per_tooth_ids = self.cutting_tool_model_id.feed_per_tooth_ids.filtered(
lambda r: int(r.blade_diameter) == int(self.specification_id.blade_diameter))
elif self.cutting_tool_type == '夹头':
self.cutting_tool_clamping_length = self.specification_id.clamping_length
self.cutting_tool_clamping_tolerance = self.specification_id.clamping_tolerance
self.cutting_tool_clamping_diameter_min = self.specification_id.min_clamping_diameter
self.cutting_tool_clamping_diameter_min = self.specification_id.max_clamping_diameter
self.cutting_tool_clamping_way = self.specification_id.clamping_mode
@@ -214,7 +211,7 @@ class ResProductMo(models.Model):
self.cutting_tool_jump_accuracy = self.specification_id.run_out_accuracy
self.cutting_tool_max_load_capacity = self.specification_id.max_load_capacity
self.cutting_tool_er_size_model = self.specification_id.er_size_model
self.cutting_tool_handle_ids = self.cutting_tool_model_id.handle_ids
self.cutting_tool_handle_id = self.cutting_tool_model_id.handle_id.id
self.cooling_suit_type_ids = self.specification_id.cooling_jacket
elif self.cutting_tool_type == '刀片':
self.cutting_tool_total_length = self.specification_id.total_length
@@ -228,14 +225,12 @@ class ResProductMo(models.Model):
self.cutting_tool_inscribed_circle_tolerance = self.specification_id.inscribed_circle_tolerance
self.cutting_tool_install_aperture_diameter = self.specification_id.install_aperture_diameter
self.cutting_tool_chip_breaker_groove = self.specification_id.chip_breaker_groove
# self.cutting_tool_cut_depth_max = self.specification_id.blade_blade_number
self.cutting_tool_chip_breaker_type_code = self.specification_id.chip_breaker_type_code
self.cutting_tool_blade_blade_number = self.specification_id.blade_blade_number
self.cutting_tool_blade_width = self.specification_id.blade_width
self.cutting_tool_rear_angle = self.specification_id.relief_angle
self.cutting_tool_main_included_angle = self.specification_id.main_included_angle
self.cutting_tool_top_angle = self.specification_id.top_angle
self.cutting_tool_blade_tip_dip_angle = self.specification_id.blade_tip_dip_angle
self.cutting_tool_side_cutting_edge_angle = self.specification_id.side_cutting_edge_angle
self.cutting_tool_pitch = self.specification_id.pitch
self.cutting_tool_bladed_teeth_model = self.specification_id.blade_teeth_model
self.cutting_tool_thickness_tolerance = self.specification_id.thickness_tolerance
@@ -257,13 +252,20 @@ class ResProductMo(models.Model):
self.cutting_tool_inscribed_circle_tolerance = self.specification_id.inscribed_circle_tolerance
self.cutting_tool_install_aperture_diameter = self.specification_id.install_aperture_diameter
self.cutting_tool_chip_breaker_groove = self.specification_id.chip_breaker_groove
# self.cutting_tool_cut_depth_max = self.specification_id.blade_blade_number
self.cutting_tool_chip_breaker_type_code = self.specification_id.chip_breaker_type_code
self.cutting_tool_blade_blade_number = self.specification_id.blade_blade_number
self.cutting_tool_blade_width = self.specification_id.blade_width
self.cutting_tool_rear_angle = self.specification_id.relief_angle
self.cutting_tool_main_included_angle = self.specification_id.main_included_angle
self.cutting_tool_top_angle = self.specification_id.top_angle
self.cutting_tool_blade_tip_dip_angle = self.specification_id.blade_tip_dip_angle
self.cutting_tool_screw = self.specification_id.screw
self.cutting_tool_wrench = self.specification_id.spanner
self.cutting_tool_blade_id = self.specification_id.blade_id.id
self.cutting_tool_is_cooling_hole = self.specification_id.is_cooling_hole
self.cutting_tool_locating_slot_code = self.specification_id.locating_slot_code
self.cutting_tool_install_blade_tip_num = self.specification_id.install_blade_tip_num
self.cutting_tool_installing_structure = self.specification_id.installing_structure
self.cutting_tool_cut_depth_max = self.specification_id.cut_depth_max
if self.cutting_tool_type == '刀盘':
self.cutting_tool_blade_length = self.specification_id.blade_length
self.cutting_tool_cutter_head_diameter = self.specification_id.cutter_head_diameter
@@ -272,17 +274,27 @@ class ResProductMo(models.Model):
self.cutting_tool_knife_head_height = self.specification_id.knife_head_height
self.cutting_tool_knife_head_width = self.specification_id.knife_head_width
self.cutting_tool_knife_head_length = self.specification_id.knife_head_length
self.cutting_tool_tool_shim = self.specification_id.tool_shim
self.cutting_tool_cotter_pin = self.specification_id.cotter_pin
self.cutting_tool_pressing_plate = self.specification_id.pressing_plate
elif self.cutting_tool_type == '刀柄':
self.cutting_tool_total_length = self.specification_id.total_length
self.cutting_tool_standard_speed = self.specification_id.standard_rotate_speed
self.cutting_tool_speed_max = self.specification_id.max_rotate_speed
self.cutting_tool_change_time = self.specification_id.tool_changing_time
self.cutting_tool_total_length = self.specification_id.total_length
self.cutting_tool_clamping_diameter_max = self.specification_id.max_clamping_diameter
self.cutting_tool_clamping_diameter_min = self.specification_id.min_clamping_diameter
self.cutting_tool_flange_length = self.specification_id.flange_shank_length
self.cutting_tool_shank_outer_diameter = self.specification_id.handle_external_diameter
self.cutting_tool_shank_inner_diameter = self.specification_id.handle_inside_diameter
self.cutting_tool_flange_diameter = self.specification_id.flange_diameter
self.cutting_tool_fit_chuck_size = self.specification_id.fit_chuck_size
self.cutting_tool_dynamic_balance_class = self.specification_id.dynamic_balance_class
self.cutting_tool_is_high_speed_cutting = self.specification_id.is_quick_cutting
self.cutting_tool_is_safety_lock = self.specification_id.is_safe_lock
self.cutting_tool_fit_nut_model = self.specification_id.nut
self.cutting_tool_wrench = self.specification_id.spanner
self.cutting_tool_chuck_id = self.specification_id.chuck_id.id
self.cutting_tool_jump_accuracy = self.specification_id.diameter_slip_accuracy
self.cutting_tool_taper_shank_model = self.specification_id.taper_shank_model
self.suitable_machining_method_ids = [(6, 0, [])] if not \
self.cutting_tool_model_id.suitable_machining_method_ids \
else [(6, 0, self.cutting_tool_model_id.suitable_machining_method_ids.ids)]
@@ -350,12 +362,12 @@ class ResProductMo(models.Model):
raise ValidationError("请选择压紧方式")
if self.cutting_tool_type == '刀片':
if not self.suitable_coolant_ids:
raise ValidationError("请选择适合冷却")
raise ValidationError("请选择适合冷却方式")
elif self.cutting_tool_type == '整体式刀具':
if not self.handle_type_id:
raise ValidationError("请选择柄部类型")
if not self.suitable_coolant_ids:
raise ValidationError("请选择适合冷却")
raise ValidationError("请选择适合冷却方式")
if not self.suitable_machining_method_ids:
raise ValidationError("请选择适合加工方式")
if not self.blade_tip_characteristics_id:
@@ -369,11 +381,8 @@ class ResProductMo(models.Model):
cutting_tool_rear_angle = fields.Integer('后角(°)')
cutting_tool_main_included_angle = fields.Integer('主偏角(°)')
# 适用夹头型号可以多选
cutting_tool_chuck_ids = fields.Many2many(
cutting_tool_chuck_id = fields.Many2one(
'sf.cutting_tool.standard.library',
relation='product_cutting_tool_library_handle_chuck_rel',
column1='model_id_1',
column2='model_id_2',
domain="[('cutting_tool_type', '=', '夹头')]",
string='适用夹头型号')
# 刀片参数
@@ -384,6 +393,7 @@ class ResProductMo(models.Model):
cutting_tool_install_aperture_diameter = fields.Float('安装孔直径(mm)')
cutting_tool_chip_breaker_groove = fields.Selection([('', ''), ('单面', '单面'), ('双面', '双面')],
string='有无断屑槽')
cutting_tool_chip_breaker_type_code = fields.Char('断屑槽型代号')
cutting_tool_bladed_teeth_model = fields.Selection(
[('', ''), ('V牙型', 'V牙型'), ('米制全牙型', '米制全牙型'), ('美制全牙型', '美制全牙型'),
('惠氏全牙型', '惠氏全牙型'), ('BSPT全牙型', 'BSPT全牙型'), ('NPT全牙型', 'NPT全牙型'),
@@ -395,8 +405,6 @@ class ResProductMo(models.Model):
('7', '7'), ('8', '8'), ('9', '9'), ('10', '10')],
string='刀片的刃数(个)')
cutting_tool_blade_tip_dip_angle = fields.Integer('刀尖倾角(°)')
cutting_tool_side_cutting_edge_angle = fields.Integer('侧切削角(°)')
cutting_tool_thread_model = fields.Selection([('', ''), ('外螺纹', '外螺纹'), ('内螺纹', '内螺纹')],
string='螺纹类型')
cutting_tool_thread_num = fields.Float('每英寸螺纹数(tpi)')
@@ -429,13 +437,10 @@ class ResProductMo(models.Model):
cutting_tool_blade_diameter = fields.Float('刃径/刃部直径(mm)')
cutting_tool_cutter_arbor_diameter = fields.Float('刀杆直径(mm)')
cutting_tool_min_machining_aperture = fields.Integer('最小加工孔径(mm)')
cutting_tool_install_blade_tip_num = fields.Integer('可装刀片数/齿数(个)', size=20)
cutting_tool_install_blade_tip_num = fields.Integer('可装刀片数/齿数(个)')
cutting_tool_installing_structure = fields.Char('安装结构', size=20)
cutting_tool_blade_ids = fields.Many2many(
cutting_tool_blade_id = fields.Many2one(
'sf.cutting_tool.standard.library',
relation='product_cutting_tool_library_pad_blade_rel',
column1='model_id_1',
column2='model_id_2',
domain="[('cutting_tool_type', '=', '刀片')]",
string='适用刀片型号' # 使用空列表作为默认值
)
@@ -451,24 +456,22 @@ class ResProductMo(models.Model):
cutting_tool_interface_diameter = fields.Float('接口直径(mm)')
# 刀柄参数
cutting_tool_shank_outer_diameter = fields.Float('柄部外径(mm)')
cutting_tool_shank_inner_diameter = fields.Float('柄部内径(mm)')
cutting_tool_clamping_length = fields.Float('夹持长度(mm)')
cutting_tool_clamping_tolerance = fields.Float('夹持公差(mm)')
cutting_tool_clamping_diameter_max = fields.Float('最大夹持直径')
cutting_tool_clamping_diameter_min = fields.Float('最小夹持直径')
cutting_tool_flange_length = fields.Float('法兰柄长(mm)')
cutting_tool_flange_diameter = fields.Float('法兰直径(mm)')
cutting_tool_is_rough_finish = fields.Boolean('可粗加工', default=False)
cutting_tool_is_finish = fields.Boolean('可精加工', default=False)
cutting_tool_is_drill_hole = fields.Boolean('可钻孔', default=False)
cutting_tool_is_safety_lock = fields.Boolean('有无安全锁', default=False)
cutting_tool_is_high_speed_cutting = fields.Boolean('可高速切削', default=False)
cutting_tool_change_time = fields.Integer('换刀时间(s)')
cutting_tool_clamping_way = fields.Char('夹持方式')
cutting_tool_fit_chuck_size = fields.Char('适配夹头尺寸')
cutting_tool_taper_shank_model = fields.Char('锥柄型号')
cutting_tool_standard_speed = fields.Integer('标准转速(n/min)')
cutting_tool_speed_max = fields.Integer('最大转速(n/min)')
cutting_tool_cooling_type = fields.Char('冷却类型')
cutting_tool_dynamic_balance_class = fields.Char('动平衡等级')
cutting_tool_fit_nut_model = fields.Char('适用锁紧螺母型号')
# 夹头参数
cutting_tool_taper = fields.Integer('锥度(°)')
cutting_tool_top_diameter = fields.Float('顶部直径')
@@ -476,38 +479,22 @@ class ResProductMo(models.Model):
cutting_tool_inner_diameter = fields.Float('内径(mm)')
cooling_suit_type_ids = fields.Char('适用冷却套型号')
cutting_tool_max_load_capacity = fields.Float('最大负载能力(kg)')
cutting_tool_er_size_model = fields.Char('ER尺寸型号')
cutting_tool_handle_ids = fields.Many2many(
cutting_tool_er_size_model = fields.Char('尺寸型号')
# cutting_tool_handle_ids = fields.Many2many(
# 'sf.cutting_tool.standard.library',
# relation='product_cutting_tool_library_chuck_handle_rel',
# column1='model_id_1',
# column2='model_id_2',
# domain="[('cutting_tool_type', '=', '刀柄')]",
# string='适用刀柄型号'
# )
cutting_tool_handle_id = fields.Many2one(
'sf.cutting_tool.standard.library',
relation='product_cutting_tool_library_chuck_handle_rel',
column1='model_id_1',
column2='model_id_2',
domain="[('cutting_tool_type', '=', '刀柄')]",
string='适用刀柄型号'
)
# 夹具参数
fixture_material_id = fields.Many2one('sf.fixture.material', string="夹具物料")
fixture_model_id = fields.Many2one('sf.fixture.model', string="夹具型号")
fixture_material_type = fields.Char(string="夹具物料类型", related='fixture_material_id.name')
fixture_multi_mounting_type_id = fields.Many2one('sf.multi_mounting.type', string="联装类型")
fixture_clamping_way = fields.Char(string="装夹方式")
fixture_port_type = fields.Char(string="接口类型")
fixture_model_file = fields.Binary(string="3D模型图")
fixture_clamp_workpiece_length_max = fields.Integer(string="夹持工件长度max(mm)")
fixture_clamp_workpiece_width_max = fields.Integer(string="夹持工件宽度max(mm)")
fixture_clamp_workpiece_height_max = fields.Integer(string="夹持工件高度max(mm)")
fixture_clamp_workpiece_diameter_max = fields.Float(string="夹持工件直径max(mm)", digits=(16, 6))
fixture_maximum_carrying_weight = fields.Float(string="最大承载重量(kg)", digits=(16, 4))
fixture_maximum_clamping_force = fields.Integer(string="最大夹持力(n)")
fixture_driving_way = fields.Char(string="驱动方式")
fixture_apply_machine_tool_type_ids = fields.Many2many('sf.machine_tool.type', 'rel_product_machine_tool_type',
string="适用机床型号")
fixture_through_hole_size = fields.Integer(string="过孔大小(mm)")
fixture_screw_size = fields.Integer(string="螺牙大小(mm)")
# 注册状态
register_state = fields.Selection([('未注册', '未注册'), ('已注册', '已注册'), ('注册失败', '注册失败')],
string='注册状态', default='未注册')
@@ -533,48 +520,12 @@ class ResProductMo(models.Model):
if self.tool_thickness > 1000000:
raise ValidationError("厚度不能超过1000000")
@api.constrains('fixture_clamp_workpiece_length_max')
def _check_fixture_clamp_workpiece_length_max_size(self):
if self.fixture_clamp_workpiece_length_max > 1000000:
raise ValidationError("夹持工件长度MAX不能超过1000000")
@api.constrains('fixture_clamp_workpiece_width_max')
def _check_fixture_clamp_workpiece_width_max_size(self):
if self.fixture_clamp_workpiece_width_max > 1000000:
raise ValidationError("夹持工件宽度MAX不能超过1000000")
@api.constrains('fixture_clamp_workpiece_height_max')
def _check_fixture_clamp_workpiece_height_max_size(self):
if self.fixture_clamp_workpiece_height_max > 1000000:
raise ValidationError("夹持工件高度MAX不能超过1000000")
@api.constrains('fixture_maximum_clamping_force')
def _check_fixture_maximum_clamping_force_size(self):
if self.fixture_maximum_clamping_force > 100000000:
raise ValidationError("最大夹持力不能超过100000000")
@api.constrains('fixture_through_hole_size')
def _check_fixture_through_hole_size_size(self):
if self.fixture_through_hole_size > 1000000:
raise ValidationError("过孔大小不能超过1000000")
@api.constrains('fixture_screw_size')
def _check_fixture_through_hole_size_size(self):
if self.fixture_screw_size > 1000000:
raise ValidationError("螺牙大小不能超过1000000")
def _json_apply_machine_tool_type_item_code(self, item):
code_arr = []
for i in item.product_id.fixture_apply_machine_tool_type_ids:
code_arr.append(i.code)
return code_arr
def _json_chuck_item_code(self, item):
code_arr = []
for i in item.product_id.cutting_tool_chuck_ids:
code_arr.append(i.code)
return code_arr
def _json_cutter_bar_item_code(self, item):
code_arr = []
for i in item.product_id.cutting_tool_cutter_bar_ids:
@@ -587,18 +538,6 @@ class ResProductMo(models.Model):
code_arr.append(i.code)
return code_arr
def _json_blade_item_code(self, item):
code_arr = []
for i in item.product_id.cutting_tool_blade_ids:
code_arr.append(i.code)
return code_arr
def _json_handle_item_code(self, item):
code_arr = []
for i in item.product_id.cutting_tool_handle_ids:
code_arr.append(i.code)
return code_arr
def _get_ids(self, param):
type_ids = []
if not param:
@@ -614,42 +553,6 @@ class ResProductMo(models.Model):
self.detailed_type = 'product'
self.sale_ok = False
@api.onchange('fixture_material_id')
def _onchange_fixture_material_id(self):
for item in self:
if item.fixture_material_id.id != item.fixture_model_id.fixture_material_id.id:
item.fixture_model_id = False
@api.onchange('fixture_model_id')
def _onchange_fixture_model_id(self):
for item in self:
if self.fixture_material_type in ['气动夹具', '转接板(锁板)夹具', '磁吸夹具', '虎钳夹具', '零点卡盘']:
item.brand_id = item.fixture_model_id.brand_id.id
item.fixture_multi_mounting_type_id = item.fixture_model_id.multi_mounting_type_id.id
item.fixture_model_file = item.fixture_model_id.model_file
item.tool_length = item.fixture_model_id.length
item.tool_width = item.fixture_model_id.width
item.tool_height = item.fixture_model_id.height
item.tool_weight = item.fixture_model_id.weight
item.materials_type_id = item.fixture_model_id.materials_model_id.id
item.fixture_maximum_carrying_weight = item.fixture_model_id.maximum_carrying_weight
item.fixture_maximum_clamping_force = item.fixture_model_id.maximum_clamping_force
if self.fixture_material_type in ['零点卡盘', '转接板(锁板)夹具']:
item.fixture_clamping_way = item.fixture_model_id.clamping_way
item.fixture_port_type = item.fixture_model_id.port_type
if self.fixture_material_type in ['气动夹具', '转接板(锁板)夹具', '磁吸夹具']:
item.fixture_driving_way = item.fixture_model_id.driving_way
if self.fixture_material_type in ['气动夹具', '磁吸夹具', '虎钳夹具', '零点卡盘']:
item.fixture_through_hole_size = item.fixture_model_id.through_hole_size
item.fixture_screw_size = item.fixture_model_id.screw_size
if self.fixture_material_type in ['气动夹具', '转接板(锁板)夹具', '磁吸夹具', '虎钳夹具']:
item.fixture_clamp_workpiece_length_max = item.fixture_model_id.clamp_workpiece_length_max
item.fixture_clamp_workpiece_width_max = item.fixture_model_id.clamp_workpiece_width_max
item.fixture_clamp_workpiece_height_max = item.fixture_model_id.clamp_workpiece_height_max
item.fixture_clamp_workpiece_diameter_max = item.fixture_model_id.clamp_workpiece_diameter_max
item.fixture_apply_machine_tool_type_ids = self._get_ids(
item.fixture_model_id.apply_machine_tool_type_ids)
def _get_volume_uom_id_from_ir_config_parameter(self):
product_length_in_feet_param = self.env['ir.config_parameter'].sudo().get_param('product.volume_in_cubic_feet')
if product_length_in_feet_param == '1':
@@ -826,6 +729,121 @@ class ResProductMo(models.Model):
return base64_data
class ResProductFixture(models.Model):
_inherit = 'product.template'
_description = '夹具产品信息'
fixture_model_id = fields.Many2one('sf.fixture.model', '夹具型号')
specification_fixture_id = fields.Many2one('sf.fixture.materials.basic.parameters', '夹具规格')
fixture_material_id = fields.Many2one('sf.fixture.material', string="夹具物料")
fixture_material_type = fields.Char(string="夹具物料类型", related='fixture_material_id.name')
multi_mounting_type_id = fields.Many2one('sf.multi_mounting.type', string="联装类型")
model_file = fields.Binary(string="3D模型图")
# 夹具物料基本参数
diameter = fields.Float('直径(mm)', digits=(16, 2))
# '零点卡盘' 字段
weight = fields.Float('重量(mm)', digits=(16, 2))
orientation_dish_diameter = fields.Float('定位盘直径(mm)', digits=(16, 2))
clamping_diameter = fields.Float('装夹直径(mm)', digits=(16, 2))
clamping_num = fields.Selection([('1', '1'), ('2', '2'), ('4', '4'), ('6', '6'), ('8', '8')], string='装夹单元数')
chucking_power_max = fields.Float('最大夹持力(KN)', digits=(16, 2))
repeated_positioning_accuracy = fields.Char('重复定位精度(mm)', size=20)
boolean_transposing_hole = fields.Boolean('是否有转位孔')
unlocking_method = fields.Selection(
[('手动', '手动'), ('气动', '气动'), ('液压', '液压'), ('电动', '电动'), ('其他', '其他')], string='解锁方式')
boolean_chip_blowing_function = fields.Boolean('是否有吹屑功能')
carrying_capacity_max = fields.Float('最大承载重量(kg)', digits=(16, 2))
rigidity = fields.Integer('硬度HRC')
materials_model_id = fields.Many2one('sf.materials.model', '夹具材质')
machine_tool_type_id = fields.Many2one('sf.machine_tool.type', '适用机床型号')
# ’零点托盘‘ 字段
connector_diameter = fields.Selection([('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('8', '8')],
string='连接头直径(mm)')
way_to_install = fields.Selection(
[('接口式', '接口式'), ('螺栓固定', '螺栓固定'), ('磁吸式', '磁吸式'), ('其他', '其他')], string='安装方式')
type_of_drive = fields.Selection(
[('气动式', '气动式'), ('液压式', '液压式'), ('机械式', '机械式'), ('电动式', '电动式'), ('其他', '其他')],
string='驱动方式')
# ’气动夹具‘ 字段
gripper_length_min = fields.Float('夹持工件最小长度(mm)', digits=(16, 2))
gripper_width_min = fields.Float('夹持工件最小宽度(mm)', digits=(16, 2))
gripper_height_min = fields.Float('夹持工件最小高度(mm)', digits=(16, 2))
gripper_diameter_min = fields.Float('夹持工件最小直径(mm)', digits=(16, 2))
gripper_length_max = fields.Float('夹持工件最大长度(mm)', digits=(16, 2))
gripper_width_max = fields.Float('夹持工件最大宽度(mm)', digits=(16, 2))
gripper_height_max = fields.Float('夹持工件最大高度(mm)', digits=(16, 2))
gripper_diameter_max = fields.Float('夹持工件最大直径(mm)', digits=(16, 2))
rated_air_pressure = fields.Float('额定气压(Mpa)', digits=(16, 2))
interface_materials_model_id = fields.Many2one('sf.materials.model', '接口类型')
# ‘虎钳夹具' 字段
transverse_groove = fields.Float('横向配合槽n(mm)', digits=(16, 2))
longitudinal_fitting_groove = fields.Float('纵向配合槽l(mm)', digits=(16, 2))
# '磁吸夹具' 字段
height_tolerance_value = fields.Char('高度公差(mm)')
rated_adsorption_force = fields.Float('额定吸附力(N/cm²)', digits=(16, 2))
magnetic_field_height = fields.Float('磁场高度(mm)', digits=(16, 2))
magnetic_pole_plate_grinding_allowance = fields.Float('磁极板磨削余量(mm)', digits=(16, 2))
# '转接板(锁板)夹具' 字段
screw_size = fields.Float('螺牙大小(mm)', digits=(16, 2))
via_hole_diameter = fields.Float('过孔直径(mm)', digits=(16, 2))
# '三爪卡盘' 字段
mounting_hole_depth = fields.Float('安装孔深度(mm)', digits=(16, 2))
centering_diameter = fields.Float('定心直径(mm)', digits=(16, 2))
@api.onchange('specification_fixture_id')
def _onchange_specification_fixture_id(self):
if self.specification_fixture_id:
self.length = self.specification_fixture_id.length
self.width = self.specification_fixture_id.width
self.height = self.specification_fixture_id.height
self.weight = self.specification_fixture_id.weight
self.diameter = self.specification_fixture_id.diameter
self.orientation_dish_diameter = self.specification_fixture_id.orientation_dish_diameter
self.clamping_diameter = self.specification_fixture_id.clamping_diameter
self.clamping_num = self.specification_fixture_id.clamping_num
self.chucking_power_max = self.specification_fixture_id.chucking_power_max
self.repeated_positioning_accuracy = self.specification_fixture_id.repeated_positioning_accuracy
self.boolean_transposing_hole = self.specification_fixture_id.boolean_transposing_hole
self.unlocking_method = self.specification_fixture_id.unlocking_method
self.boolean_chip_blowing_function = self.specification_fixture_id.boolean_chip_blowing_function
self.carrying_capacity_max = self.specification_fixture_id.carrying_capacity_max
self.rigidity = self.specification_fixture_id.rigidity
self.materials_model_id = self.specification_fixture_id.materials_model_id
self.machine_tool_type_id = self.specification_fixture_id.machine_tool_type_id
self.connector_diameter = self.specification_fixture_id.connector_diameter
self.way_to_install = self.specification_fixture_id.way_to_install
self.type_of_drive = self.specification_fixture_id.type_of_drive
self.gripper_length_min = self.specification_fixture_id.gripper_length_min
self.gripper_width_min = self.specification_fixture_id.gripper_width_min
self.gripper_height_min = self.specification_fixture_id.gripper_height_min
self.gripper_diameter_min = self.specification_fixture_id.gripper_diameter_min
self.gripper_length_max = self.specification_fixture_id.gripper_length_max
self.gripper_width_max = self.specification_fixture_id.gripper_width_max
self.gripper_height_max = self.specification_fixture_id.gripper_height_max
self.gripper_diameter_max = self.specification_fixture_id.gripper_diameter_max
self.rated_air_pressure = self.specification_fixture_id.rated_air_pressure
self.interface_materials_model_id = self.specification_fixture_id.interface_materials_model_id
self.transverse_groove = self.specification_fixture_id.transverse_groove
self.longitudinal_fitting_groove = self.specification_fixture_id.longitudinal_fitting_groove
self.height_tolerance_value = self.specification_fixture_id.height_tolerance_value
self.rated_adsorption_force = self.specification_fixture_id.rated_adsorption_force
self.magnetic_field_height = self.specification_fixture_id.magnetic_field_height
self.magnetic_pole_plate_grinding_allowance = self.specification_fixture_id.magnetic_pole_plate_grinding_allowance
self.screw_size = self.specification_fixture_id.screw_size
self.via_hole_diameter = self.specification_fixture_id.via_hole_diameter
self.mounting_hole_depth = self.specification_fixture_id.mounting_hole_depth
self.centering_diameter = self.specification_fixture_id.centering_diameter
class SfMaintenanceEquipmentAndProductTemplate(models.Model):
_inherit = 'maintenance.equipment'
_description = '设备'
@@ -852,6 +870,11 @@ class SfMaintenanceEquipmentTool(models.Model):
_description = '机床刀位'
equipment_id = fields.Many2one('maintenance.equipment', string='设备')
code = fields.Char('机床刀位号')
name = fields.Char('刀位号', compute='_compute_name')
# 待删除字段
product_template_id = fields.Many2one('product.template', string='功能刀具名称',
domain="[('categ_type', '=', '刀具')]")
image_1920 = fields.Binary('图片', related='product_template_id.image_1920')
@@ -864,9 +887,6 @@ class SfMaintenanceEquipmentTool(models.Model):
life_value_max = fields.Char('最大寿命值')
alarm_value = fields.Char('报警值')
used_value = fields.Char('已使用值')
code = fields.Char('机床刀位号')
name = fields.Char('', compute='_compute_name')
@api.depends('code')
def _compute_name(self):

View File

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import base64
import qrcode
from collections import defaultdict, namedtuple
import logging
import json
@@ -12,6 +13,7 @@ from odoo.tools import float_compare
from odoo.addons.stock.models.stock_rule import ProcurementException
from odoo.addons.sf_base.commons.common import Common
from odoo.exceptions import UserError
from io import BytesIO
class StockRule(models.Model):
@@ -202,8 +204,7 @@ class StockRule(models.Model):
sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)])
if sale_order:
sale_order.write({'schedule_status': 'to schedule'})
self.env['sf.production.plan'].sudo().with_company(company_id). \
create({
self.env['sf.production.plan'].sudo().with_company(company_id).create({
'name': production.name,
'order_deadline': sale_order.deadline_of_delivery,
'production_id': production.id,
@@ -265,6 +266,60 @@ class ProductionLot(models.Model):
return "%s-%s-%03d" % (product.cutting_tool_model_id.code, now, 1)
return "%s-%03d" % (product.name, 1)
qr_code_image = fields.Binary(string='二维码', compute='_generate_qr_code')
@api.depends('name')
def _generate_qr_code(self):
for record in self:
# Generate QR code
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(record.name)
qr.make(fit=True)
qr_image = qr.make_image(fill_color="black", back_color="white")
# Encode the image data in base64
image_stream = BytesIO()
qr_image.save(image_stream, format="PNG")
encoded_image = base64.b64encode(image_stream.getvalue())
record.qr_code_image = encoded_image
def print_qr_code(self):
self.ensure_one() # 确保这个方法只为一个记录调用
# if not self.lot_id:
# raise UserError("没有找到序列号。")
# 假设_lot_qr_code方法已经生成了二维码并保存在字段中
qr_code_data = self.qr_code_image
if not qr_code_data:
raise UserError("没有找到二维码数据。")
# 生成下载链接或直接触发下载
# 此处的实现依赖于你的具体需求,以下是触发下载的一种示例
attachment = self.env['ir.attachment'].sudo().create({
'datas': self.qr_code_image,
'type': 'binary',
'description': '二维码图片',
'name': self.name + '.png',
# 'res_id': invoice.id,
# 'res_model': 'stock.picking',
'public': True,
'mimetype': 'application/x-png',
# 'model_name': 'stock.picking',
})
# 返回附件的下载链接
download_url = '/web/content/%s?download=true' % attachment.id
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
return {
'type': 'ir.actions.act_url',
'url': str(base_url) + download_url,
'target': 'self',
}
class StockPicking(models.Model):
_inherit = 'stock.picking'
@@ -360,7 +415,6 @@ class ReStockMove(models.Model):
materiel_height = fields.Float(string='物料高度', digits=(16, 4))
def _get_new_picking_values_Res(self, item, sorted_workorders, rescode):
logging.info('new_picking-rescode: %s' % rescode)
return {
'name': self.env['stock.picking']._get_name_Res(rescode),
'origin': item.name,
@@ -374,167 +428,21 @@ class ReStockMove(models.Model):
'state': 'confirmed',
}
# 将采购到的夹具注册到Cloud
def _register_fixture(self):
create_url = '/api/factory_fixture_material/create'
config = self.env['res.config.settings'].get_values()
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
strurl = config['sf_url'] + create_url
for item in self:
val = {
'token': config['token'],
'name': item.product_id.name,
'brand_code': self.env['sf.machine.brand'].search([('id', '=', item.product_id.brand_id.id)]).code,
'fixture_material_code': self.env['sf.fixture.material'].search(
[('id', '=', item.product_id.fixture_material_id.id)]).code,
'fixture_multi_mounting_type_code': self.env['sf.multi_mounting.type'].search(
[('id', '=', item.product_id.fixture_multi_mounting_type_id.id)]).code,
'fixture_materials_type_code': self.env['sf.materials.model'].search(
[('id', '=', item.product_id.materials_type_id.id)]).materials_no,
'fixture_clamping_way': item.product_id.fixture_clamping_way,
'fixture_port_type': item.product_id.fixture_port_type,
'fixture_length': item.product_id.tool_length,
'fixture_width': item.product_id.tool_width,
'fixture_height': item.product_id.tool_height,
'fixture_weight': item.product_id.tool_weight,
'fixture_amount': int(item.quantity_done),
'fixture_model_file': '' if not item.product_id.fixture_model_file else base64.b64encode(
item.product_id.fixture_model_file).decode(
'utf-8'),
'fixture_clamp_workpiece_length_max': item.product_id.fixture_clamp_workpiece_length_max,
'fixture_clamp_workpiece_width_max': item.product_id.fixture_clamp_workpiece_width_max,
'fixture_clamp_workpiece_height_max': item.product_id.fixture_clamp_workpiece_height_max,
'fixture_clamp_workpiece_diameter_max': item.product_id.fixture_clamp_workpiece_diameter_max,
'fixture_maximum_carrying_weight': item.product_id.fixture_maximum_carrying_weight,
'fixture_maximum_clamping_force': item.product_id.fixture_maximum_clamping_force,
'fixture_driving_way': '' if not item.product_id.fixture_driving_way
else item.product_id.fixture_driving_way,
'fixture_apply_machine_tool_type_codes': self.env[
'product.template']._json_apply_machine_tool_type_item_code(item),
'fixture_through_hole_size': item.product_id.fixture_through_hole_size,
'fixture_screw_size': item.product_id.fixture_screw_size,
}
try:
if item.product_id.industry_code:
val['industry_code'] = item.product_id.industry_code
ret = requests.post(strurl, json={}, data=val, headers=headers)
ret = ret.json()
if ret['status'] == 200:
if not item.product_id.industry_code:
item.product_id.write({'register_state': '已注册', 'industry_code': ret['industry_code']})
else:
item.product_id.write({'register_state': '已注册'})
else:
item.product_id.write({'register_state': '注册失败'})
except Exception as e:
raise UserError("注册夹具到云端失败,请联系管理员!")
# 将采购到的刀具注册到Cloud
def _register_cutting_tool(self):
create_url = '/api/factory_cutting_tool_material/create'
config = self.env['res.config.settings'].get_values()
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
strurl = config['sf_url'] + create_url
for item in self:
val = {
'token': config['token'],
'name': item.product_id.name,
'brand_code': self.env['sf.machine.brand'].search([('id', '=', item.product_id.brand_id.id)]).code,
'cutting_tool_material_code': self.env['sf.cutting.tool.material'].search(
[('id', '=', item.product_id.cutting_tool_material_id.id)]).code,
'cutting_tool_type_code': self.env['sf.cutting.tool.type'].search(
[('id', '=', item.product_id.cutting_tool_type_id.id)]).code,
'material_model_code': self.env['sf.materials.model'].search(
[('id', '=', item.product_id.materials_type_id.id)]).materials_no,
'tool_length': item.product_id.tool_length,
'tool_width': item.product_id.tool_width,
'tool_height': item.product_id.tool_height,
'tool_thickness': item.product_id.tool_thickness,
'tool_weight': item.product_id.tool_weight,
'tool_hardness': item.product_id.tool_hardness,
'coating_material': item.product_id.coating_material,
'amount': int(item.quantity_done),
# 'model_file': '' if not item.product_id.fixture_model_file else base64.b64encode(
# item.product_id.fixture_model_file).decode(
# 'utf-8'),
'total_length': item.product_id.cutting_tool_total_length,
'shank_length': item.product_id.cutting_tool_shank_length,
'blade_length': item.product_id.cutting_tool_blade_length,
'neck_length': item.product_id.cutting_tool_neck_length,
'neck_diameter': item.product_id.cutting_tool_neck_diameter,
'shank_diameter': item.product_id.cutting_tool_shank_diameter,
'blade_tip_diameter': item.product_id.cutting_tool_blade_tip_diameter,
'blade_tip_taper': item.product_id.cutting_tool_blade_tip_taper,
'blade_helix_angle': item.product_id.cutting_tool_blade_helix_angle,
'blade_type': item.product_id.cutting_tool_blade_type,
'coarse_medium_fine': '' if item.product_id.cutting_tool_coarse_medium_fine is False
else item.product_id.cutting_tool_coarse_medium_fine,
'run_out_accuracy_max': item.product_id.cutting_tool_run_out_accuracy_max,
'run_out_accuracy_min': item.product_id.cutting_tool_run_out_accuracy_min,
'head_diameter': item.product_id.cutting_tool_head_diameter,
'diameter': item.product_id.cutting_tool_diameter,
'blade_number': '' if item.product_id.cutting_tool_blade_number is False
else item.product_id.cutting_tool_blade_number,
'front_angle': item.product_id.cutting_tool_front_angle,
'rear_angle': item.product_id.cutting_tool_rear_angle,
'main_included_angle': item.product_id.cutting_tool_main_included_angle,
'chuck_codes': self.env['product.template']._json_chuck_item_code(item),
'cutter_bar_codes': self.env['product.template']._json_cutter_bar_item_code(item),
'cutter_pad_codes': self.env['product.template']._json_cutter_pad_item_code(item),
'blade_codes': self.env['product.template']._json_blade_item_code(item),
'handle_codes': self.env['product.template']._json_handle_item_code(item),
'nut': item.product_id.cutting_tool_nut,
'top_angle': item.product_id.cutting_tool_top_angle,
'jump_accuracy': item.product_id.cutting_tool_jump_accuracy,
'working_hardness': item.product_id.cutting_tool_working_hardness,
'blade_diameter': item.product_id.cutting_tool_blade_diameter,
'wrench': item.product_id.cutting_tool_wrench,
'accuracy_level': item.product_id.cutting_tool_accuracy_level,
'clamping_way': item.product_id.cutting_tool_clamping_way,
'clamping_length': item.product_id.cutting_tool_clamping_length,
'clamping_tolerance': item.product_id.cutting_tool_clamping_tolerance,
'diameter_max': item.product_id.cutting_tool_diameter_max,
'clamping_diameter_min': item.product_id.cutting_tool_clamping_diameter_min,
'clamping_diameter_max': item.product_id.cutting_tool_clamping_diameter_max,
'detection_accuracy_max': item.product_id.cutting_tool_detection_accuracy_max,
'detection_accuracy_min': item.product_id.cutting_tool_detection_accuracy_min,
'is_rough_finish': item.product_id.cutting_tool_is_rough_finish,
'is_finish': item.product_id.cutting_tool_is_finish,
'is_drill_hole': item.product_id.cutting_tool_is_drill_hole,
'is_safety_lock': item.product_id.cutting_tool_is_safety_lock,
'is_high_speed_cutting': item.product_id.cutting_tool_is_high_speed_cutting,
'dynamic_balance_class': item.product_id.cutting_tool_dynamic_balance_class,
'change_time': item.product_id.cutting_tool_change_time,
'standard_speed': item.product_id.cutting_tool_standard_speed,
'speed_max': item.product_id.cutting_tool_speed_max,
'cooling_type': item.product_id.cutting_tool_cooling_type,
'body_accuracy': item.product_id.cutting_tool_body_accuracy,
'apply_lock_nut_model': item.product_id.apply_lock_nut_model,
'apply_lock_wrench_model': item.product_id.apply_lock_wrench_model,
'tool_taper': item.product_id.cutting_tool_taper,
'flange_length': item.product_id.cutting_tool_flange_length,
'flange_diameter': item.product_id.cutting_tool_flange_diameter,
'outer_diameter': item.product_id.cutting_tool_outer_diameter,
'inner_diameter': item.product_id.cutting_tool_inner_diameter,
'cooling_suit_type_ids': item.product_id.cooling_suit_type_ids,
'er_size_model': item.product_id.cutting_tool_er_size_model,
'image': '' if not item.product_id.image_1920 else
base64.b64encode(item.product_id.image_1920).decode('utf-8'),
}
try:
if item.product_id.industry_code:
val['industry_code'] = item.product_id.industry_code
ret = requests.post(strurl, json={}, data=val, headers=headers)
ret = ret.json()
if ret['status'] == 200:
if not item.product_id.industry_code:
item.product_id.write({'register_state': '已注册', 'industry_code': ret['industry_code']})
else:
item.product_id.write({'register_state': '已注册'})
else:
item.product_id.write({'register_state': '注册失败'})
except Exception as e:
raise UserError("注册刀具到云端失败,请联系管理员!")
def print_serial_numbers(self):
if not self.next_serial:
raise UserError(_("请先分配序列号再进行打印"))
label_data = []
for item in self.move_line_ids:
label_data.append({
'item_id': item.id,
})
if label_data:
report_template = self.env.ref('stock.label_package_template')
res = report_template.report_action(label_data)
res['id'] = report_template.id
return res
else:
raise UserError(_("没有可打印的标签数据"))
class ReStockQuant(models.Model):