diff --git a/sf_base/models/base.py b/sf_base/models/base.py index 5762822e..a6e1d4cc 100644 --- a/sf_base/models/base.py +++ b/sf_base/models/base.py @@ -77,6 +77,7 @@ class MachineTool(models.Model): b_axis = fields.Integer('B轴') c_axis = fields.Integer('C轴') remark = fields.Text('备注') + is_binding = fields.Boolean('是否绑定机床', default=False) precision = fields.Float('加工精度') control_system_id = fields.Many2one('sf.machine.control_system', string="控制系统") diff --git a/sf_bf_connect/controllers/controllers.py b/sf_bf_connect/controllers/controllers.py index 4b352dcf..819f79bc 100644 --- a/sf_bf_connect/controllers/controllers.py +++ b/sf_bf_connect/controllers/controllers.py @@ -35,66 +35,72 @@ class Sf_Bf_Connect(http.Controller): ret['delivery_end_date'], user_id) i = 1 for item in ret['bfm_process_order_list']: - product = request.env['product.template'].sudo().product_create(product_id, item, order_id, - ret['order_number'], i) - # order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item) - logging.info('order_id:%s' % order_id) - logging.info('product:%s' % product) - bom_data = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).get_bom(product) - logging.info('bom_data:%s' % bom_data) - if bom_data: - bom = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).bom_create(product, - 'normal', - False) - bom.with_user(request.env.ref("base.user_admin")).bom_create_line_has(bom_data) + product_has = request.env['product.template'].with_user(request.env.ref("base.user_admin")).search([('barcode','=', item['barcode'])]) + if product_has: + logging.info('product_has:%s' % product_has) + logging.info('barcode:%s' % item['barcode']) + order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product_has, item) else: - if product.materials_type_id.gain_way == '自加工': - # 创建胚料 - self_machining_embryo = request.env['product.template'].sudo().no_bom_product_create( - self_machining_id, - item, - order_id, 'self_machining') - # 创建胚料的bom - self_machining_bom = request.env['mrp.bom'].with_user( - request.env.ref("base.user_admin")).bom_create( - self_machining_embryo, 'normal') - # 创建胚料里bom的组件 - self_machining_bom.with_user(request.env.ref("base.user_admin")).bom_create_line( - self_machining_embryo) - # 产品配置bom - product_bom_self_machining = request.env['mrp.bom'].with_user( - request.env.ref("base.user_admin")).bom_create( - product, 'normal', False) - product_bom_self_machining.with_user(request.env.ref("base.user_admin")).bom_create_line_has( - self_machining_embryo) - elif product.materials_type_id.gain_way == '外协': - # 创建胚料 - outsource_embryo = request.env['product.template'].sudo().no_bom_product_create(outsource_id, - item, - order_id, - 'subcontract') - # 创建胚料的bom - outsource_bom = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).bom_create( - outsource_embryo, - 'subcontract', True) - # 创建胚料的bom的组件 - outsource_bom.with_user(request.env.ref("base.user_admin")).bom_create_line(outsource_embryo) - # 产品配置bom - product_bom_outsource = request.env['mrp.bom'].with_user( - request.env.ref("base.user_admin")).bom_create(product, 'normal', False) - product_bom_outsource.with_user(request.env.ref("base.user_admin")).bom_create_line_has( - outsource_embryo) - elif product.materials_type_id.gain_way == '采购': - purchase_embryo = request.env['product.template'].sudo().no_bom_product_create(purchase_id, - item, - order_id, - 'purchase') - # 产品配置bom - product_bom_purchase = request.env['mrp.bom'].with_user( - request.env.ref("base.user_admin")).bom_create(product, 'normal', False) - product_bom_purchase.with_user(request.env.ref("base.user_admin")).bom_create_line_has( - purchase_embryo) - order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item) + product = request.env['product.template'].sudo().product_create(product_id, item, order_id, + ret['order_number'], i) + # order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item) + logging.info('order_id:%s' % order_id) + logging.info('product:%s' % product) + bom_data = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).get_bom(product) + logging.info('bom_data:%s' % bom_data) + if bom_data: + bom = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).bom_create(product, + 'normal', + False) + bom.with_user(request.env.ref("base.user_admin")).bom_create_line_has(bom_data) + else: + if product.materials_type_id.gain_way == '自加工': + # 创建胚料 + self_machining_embryo = request.env['product.template'].sudo().no_bom_product_create( + self_machining_id, + item, + order_id, 'self_machining') + # 创建胚料的bom + self_machining_bom = request.env['mrp.bom'].with_user( + request.env.ref("base.user_admin")).bom_create( + self_machining_embryo, 'normal', False) + # 创建胚料里bom的组件 + self_machining_bom.with_user(request.env.ref("base.user_admin")).bom_create_line( + self_machining_embryo) + # 产品配置bom + product_bom_self_machining = request.env['mrp.bom'].with_user( + request.env.ref("base.user_admin")).bom_create( + product, 'normal', False) + product_bom_self_machining.with_user(request.env.ref("base.user_admin")).bom_create_line_has( + self_machining_embryo) + elif product.materials_type_id.gain_way == '外协': + # 创建胚料 + outsource_embryo = request.env['product.template'].sudo().no_bom_product_create(outsource_id, + item, + order_id, + 'subcontract') + # 创建胚料的bom + outsource_bom = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).bom_create( + outsource_embryo, + 'subcontract', True) + # 创建胚料的bom的组件 + outsource_bom.with_user(request.env.ref("base.user_admin")).bom_create_line(outsource_embryo) + # 产品配置bom + product_bom_outsource = request.env['mrp.bom'].with_user( + request.env.ref("base.user_admin")).bom_create(product, 'normal', False) + product_bom_outsource.with_user(request.env.ref("base.user_admin")).bom_create_line_has( + outsource_embryo) + elif product.materials_type_id.gain_way == '采购': + purchase_embryo = request.env['product.template'].sudo().no_bom_product_create(purchase_id, + item, + order_id, + 'purchase') + # 产品配置bom + product_bom_purchase = request.env['mrp.bom'].with_user( + request.env.ref("base.user_admin")).bom_create(product, 'normal', False) + product_bom_purchase.with_user(request.env.ref("base.user_admin")).bom_create_line_has( + purchase_embryo) + order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item) i += 1 res['factory_order_no'] = order_id.name return json.JSONEncoder().encode(res) diff --git a/sf_dlm/data/product_data.xml b/sf_dlm/data/product_data.xml index e3ecbfae..aad3714c 100644 --- a/sf_dlm/data/product_data.xml +++ b/sf_dlm/data/product_data.xml @@ -15,7 +15,7 @@ 原材料 - + CNC加工产品模板 @@ -31,7 +31,7 @@ serial - + 胚料自加工模板 @@ -48,7 +48,7 @@ - + 胚料外协加工模板 @@ -63,7 +63,7 @@ serial - + 胚料采购模板 diff --git a/sf_dlm/models/product_template.py b/sf_dlm/models/product_template.py index 25420671..b3c613fa 100644 --- a/sf_dlm/models/product_template.py +++ b/sf_dlm/models/product_template.py @@ -29,6 +29,7 @@ class ResProductTemplate(models.Model): materials_id = fields.Many2one('sf.production.materials', string='材料') materials_type_id = fields.Many2one('sf.materials.model', string='材料型号') single_manufacturing = fields.Boolean(string="单个制造") + model_id = fields.Many2one('ir.attachment', string='模型') # 胚料的库存路线设置 # def _get_routes(self, route_type): @@ -53,19 +54,24 @@ class ResProductTemplate(models.Model): # 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品 def product_create(self, product_id, item, order_id, order_number, i): copy_product_id = product_id.with_user(self.env.ref("base.user_admin")).copy() - # copy_product_id.product_tmpl_id.active = True + copy_product_id.product_tmpl_id.active = True + model_type = self.env['sf.model.type'].search([], limit=1) vals = { 'name': '%s-%s' % (order_id.name, i), - 'model_long': item['model_long'], - 'model_width': item['model_width'], - 'model_height': item['model_height'], + 'model_long': item['model_long'] + model_type.embryo_tolerance, + 'model_width': item['model_width'] + model_type.embryo_tolerance, + 'model_height': item['model_height'] + model_type.embryo_tolerance, + 'model_volume': (item['model_long'] + model_type.embryo_tolerance) * ( + item['model_width'] + model_type.embryo_tolerance) * ( + item['model_height'] + model_type.embryo_tolerance), 'model_type_id': 1, - 'model_machining_precision': item['model_machining_precision'], - 'model_processing_panel': 'R,U', + # 'model_machining_precision': item['model_machining_precision'], + 'model_processing_panel': 'A', + 'model_machining_precision': '±0.10mm', 'length': item['model_long'], 'width': item['model_width'], 'height': item['model_height'], - 'volume': (item['model_long'] * item['model_width'] * item['model_height']), + 'volume': item['model_long'] * item['model_width'] * item['model_height'], # 'model_price': item['price'], # 'single_manufacturing': True, 'list_price': item['price'], @@ -74,8 +80,8 @@ class ResProductTemplate(models.Model): [('materials_no', '=', item['texture_code'])]).id, 'materials_type_id': self.env['sf.materials.model'].search( [('materials_no', '=', item['texture_type_code'])]).id, - # 'model_surface_process_id': self.env['sf.production.process'].search( - # [('process_encode', '=', item['surface_process_code'])]).id, + 'model_surface_process_id': self.env['sf.production.process'].search( + [('process_encode', '=', item['surface_process_code'])]).id, # 'model_process_parameters_id': self.env['sf.processing.technology'].search( # [('process_encode', '=', item['process_parameters_code'])]).id, 'model_remark': item['remark'], @@ -85,27 +91,40 @@ class ResProductTemplate(models.Model): # 'route_ids': self._get_routes('') } copy_product_id.sudo().write(vals) - # product_id.active = False + copy_product_id.model_id = self.attachment_create(item['model_name'], item['model_data']) + product_id.product_tmpl_id.active = False return copy_product_id + def attachment_create(self, name, data): + attachment = self.env['ir.attachment'].create({ + 'datas': base64.b64encode(data), + 'type': 'binary', + 'description': '模型文件', + 'name': name + }) + return attachment + # 创建胚料 def no_bom_product_create(self, product_id, item, order_id, route_type): no_bom_copy_product_id = product_id.with_user(self.env.ref("base.user_admin")).copy() - # no_bom_copy_product_id.product_tmpl_id.active = True + no_bom_copy_product_id.product_tmpl_id.active = True materials_id = self.env['sf.production.materials'].search( [('materials_no', '=', item['texture_code'])]) materials_type_id = self.env['sf.materials.model'].search( [('materials_no', '=', item['texture_type_code'])]) + model_type = self.env['sf.model.type'].search([], limit=1) supplier = self.env['mrp.bom'].get_supplier(materials_type_id) logging.info('no_bom_copy_product_supplier-vals:%s' % supplier) vals = { 'name': '%s %s %s %s * %s * %s' % ( order_id.name, materials_id.name, materials_type_id.name, item['model_long'], item['model_width'], item['model_height']), - 'length': item['model_long'], - 'width': item['model_width'], - 'height': item['model_height'], - 'volume': item['model_long'] * item['model_width'] * item['model_height'], + 'length': item['model_long'] + model_type.embryo_tolerance, + 'width': item['model_width'] + model_type.embryo_tolerance, + 'height': item['model_height'] + model_type.embryo_tolerance, + 'volume': (item['model_long'] + model_type.embryo_tolerance) * ( + item['model_width'] + model_type.embryo_tolerance) * ( + item['model_height'] + model_type.embryo_tolerance), # 'model_price': item['price'], 'list_price': item['price'], 'materials_id': materials_id.id, @@ -131,7 +150,7 @@ class ResProductTemplate(models.Model): logging.info('no_bom_copy_product_id-seller_ids-vals:%s' % no_bom_copy_product_id.seller_ids) no_bom_copy_product_id.write(vals) logging.info('no_bom_copy_product_id-vals:%s' % vals) - # product_id.active = False + product_id.product_tmpl_id.active = False return no_bom_copy_product_id # 根据模型类型默认给模型的长高宽加配置的长度; @@ -140,11 +159,11 @@ class ResProductTemplate(models.Model): if not self.model_type_id: return model_type = self.env['sf.model.type'].search( - [('id', '=', self.model_type_id.id), ('embryo_tolerance', '=', True)]) + [('id', '=', self.model_type_id.id)]) if model_type: - self.model_long = self.model_long + 1 - self.model_width = self.model_width + 1 - self.model_height = self.model_width + 1 + self.model_long = self.model_long + embryo_tolerance + self.model_width = self.model_width + embryo_tolerance + self.model_height = self.model_width + embryo_tolerance else: return diff --git a/sf_dlm/views/product_template_view.xml b/sf_dlm/views/product_template_view.xml index f363f0b2..2ca5b634 100644 --- a/sf_dlm/views/product_template_view.xml +++ b/sf_dlm/views/product_template_view.xml @@ -101,8 +101,8 @@ - + diff --git a/sf_manufacturing/models/model_type.py b/sf_manufacturing/models/model_type.py index bdc5fc78..ecc4b7af 100644 --- a/sf_manufacturing/models/model_type.py +++ b/sf_manufacturing/models/model_type.py @@ -6,7 +6,7 @@ class ModelType(models.Model): _description = '模型类型' name = fields.Char('名称') - embryo_tolerance = fields.Boolean('胚料的容余量', default=False) + embryo_tolerance = fields.Integer('胚料的容余量') routing_tmpl_ids = fields.One2many('sf.model.type.routing.sort', 'model_type_id', '工序模板') diff --git a/sf_manufacturing/models/mrp_workcenter.py b/sf_manufacturing/models/mrp_workcenter.py index ad7a0419..db7db216 100644 --- a/sf_manufacturing/models/mrp_workcenter.py +++ b/sf_manufacturing/models/mrp_workcenter.py @@ -7,6 +7,12 @@ class ResWorkcenter(models.Model): _inherit = "mrp.workcenter" machine_tool_id = fields.Many2one('sf.machine_tool', '机床') + @api.onchange('machine_tool_id') + def get_machine_tool_is_binding(self): + print('1111111') + for item in self: + item.machine_tool_id.is_binding = False + equipment_ids = fields.One2many( 'maintenance.equipment', 'workcenter_id', string="Maintenance Equipment", check_company=True) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 2fb49715..eb471618 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -341,13 +341,13 @@ class CNCprocessing(models.Model): depth_of_processing_z = fields.Char('加工深度(Z)') cutting_tool_extension_length = fields.Char('刀具伸出长度') cutting_tool_handle_type = fields.Char('刀柄型号') - estimated_processing_time = fields.Datetime('预计加工时间') + estimated_processing_time = fields.Char('预计加工时间') remark = fields.Text('备注') workorder_id = fields.Many2one('mrp.workorder', string="工单") # mrs下发编程单创建CNC加工 def cnc_processing_create(self, obj): - workorder = self.env['mrp.workorder'].search([('production_id.name', '=', obj['manufacturing_order_no']), + workorder = self.env['mrp.workorder'].search([('production_id.name', '=', obj['production_order_no']), ('processing_panel', '=', obj['processing_panel']), ('routing_type', '=', 'CNC加工')]) vals = { diff --git a/sf_manufacturing/views/model_type_view.xml b/sf_manufacturing/views/model_type_view.xml index 58fd70be..58d1bf94 100644 --- a/sf_manufacturing/views/model_type_view.xml +++ b/sf_manufacturing/views/model_type_view.xml @@ -31,7 +31,7 @@
- + diff --git a/sf_manufacturing/views/mrp_workcenter_views.xml b/sf_manufacturing/views/mrp_workcenter_views.xml index 11777e58..d500e3b6 100644 --- a/sf_manufacturing/views/mrp_workcenter_views.xml +++ b/sf_manufacturing/views/mrp_workcenter_views.xml @@ -81,7 +81,7 @@ - + diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index 969cdeb2..76fc34c5 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -32,20 +32,32 @@ class Sf_Mrs_Connect(http.Controller): logging.info('model_code:%s' % model_code) server_dir = cnc.with_user(request.env.ref("base.user_admin")).download_file_tmp(model_code, processing_panel) - cnc_file_path = os.path.join('/', server_dir, cnc.program_name + '.nc') - logging.info('cnc_file_path:%s' % cnc_file_path) - cnc.with_user(request.env.ref("base.user_admin")).write_file(cnc_file_path, cnc) - logging.info('get_cnc_processing_create:%s' % '111111111111111') - # for root, dirs, files in os.walk(server_dir): - # for f in files: - # if os.path.splitext(f)[1] == ".pdf": - # pdf_path = os.path.splitext(file)[1] + '.PDF' - # - # if pdf_path != False: - # if not cnc.workorder_id.cnc_worksheet: - # cnc.workorder_id.cnc_worksheet = base64.b64encode(open(cnc_pdf_path, 'rb').read()) - # else: - # logging.info('break:%s' % 'break') - # break + # cnc_file_path = os.path.join('/', server_dir, cnc.program_name + '.nc') + # logging.info('cnc_file_path:%s' % cnc_file_path) + # cnc.with_user(request.env.ref("base.user_admin")).write_file(cnc_file_path, cnc) + logging.info('server_dir:%s' % server_dir) + for root, dirs, files in os.walk(server_dir): + for f in files: + logging.info('f:%s' % f) + logging.info('f[0]:%s' % f.split('.')[0]) + if os.path.splitext(f)[1] == ".pdf": + full_path = os.path.join(server_dir, root, f) + logging.info('pdf:%s' % full_path) + if full_path != False: + if not cnc.workorder_id.cnc_worksheet: + cnc.workorder_id.cnc_worksheet = base64.b64encode(open(full_path, 'rb').read()) + else: + logging.info('break:%s' % 'break') + continue + else: + logging.info('cnc.program_name:%s' % cnc.program_name) + if cnc.program_name == f.split('.')[0]: + logging.info('f[0]:%s' % f[0]) + cnc_file_path = os.path.join(server_dir, root, f) + logging.info('cnc_file_path:%s' % cnc_file_path) + cnc.with_user(request.env.ref("base.user_admin")).write_file(cnc_file_path, cnc) + else: + continue + except Exception as e: logging.info('get_cnc_processing_create error:%s' % e) diff --git a/sf_mrs_connect/models/ftp_operate.py b/sf_mrs_connect/models/ftp_operate.py index a71ee83f..655c50e6 100644 --- a/sf_mrs_connect/models/ftp_operate.py +++ b/sf_mrs_connect/models/ftp_operate.py @@ -25,15 +25,16 @@ class FtpController(): # 下载目录下的文件 def download_file_tree(self, target_dir, serverdir): - self.ftp.cwd(target_dir) # 切换工作路径 if not os.path.exists(serverdir): os.makedirs(serverdir) - remotenames = self.ftp.nlst() - for file in remotenames: - server = os.path.join(serverdir, file) - if file.find(".") != -1: - self.download_file(server, file) - return + self.ftp.cwd(target_dir) # 切换工作路径 + remotenames = self.ftp.nlst() + for file in remotenames: + server = os.path.join(serverdir, file) + if file.find(".") != -1: + self.download_file(server, file) + else: + return # 下载指定目录下的指定文件 def download_file(self, serverfile, remotefile): diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py index 9bf6f2b1..ffcd27f5 100644 --- a/sf_sale/models/sale_order.py +++ b/sf_sale/models/sale_order.py @@ -44,6 +44,7 @@ class ReSaleOrder(models.Model): product.model_machining_precision, product.materials_id.name), 'price_unit': product.list_price, + 'route_ids': product.route_ids, 'product_uom_qty': item['number'] } return self.env['sale.order.line'].create(vals)