优化代码格式至PEP8格式

This commit is contained in:
mgw
2023-11-17 17:49:08 +08:00
parent c3ee544ca6
commit 5bc5766507

View File

@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
import base64
import json, requests
from odoo import models, fields, api, _
import json
import requests
from datetime import datetime, timedelta
from odoo import models, fields, api, _
from odoo.exceptions import UserError, ValidationError
@@ -47,16 +48,6 @@ class sf_production_plan(models.Model):
sequence = fields.Integer(string='序号', copy=False, readonly=True, index=True)
current_operation_name = fields.Char(string='当前工序名称', size=64, default='生产计划')
# state = fields.Selection([
# ('未排程', '未排程'), ('已排程', '已排程')], string='State', copy=False, index=True, readonly=True,
# store=True, tracking=True)
# orderpoint_id = fields.Many2one('stock.warehouse.orderpoint', compute='_compute_orderpoint_id')
# location_src_id = fields.Many2one('stock.location', 'Components Location', compute='_compute_orderpoint_id', active=False)
# location_dest_id = fields.Many2one('stock.location', 'Finished Products Location', compute='_compute_orderpoint_id')
# picking_type_id = fields.Many2one('stock.picking.type', 'Operation Type', compute='_compute_orderpoint_id')
# move_dest_ids = fields.One2many('stock.move', 'created_production_id', compute='_compute_orderpoint_id')
@api.model
def get_import_templates(self):
"""returns the xlsx import template file"""
@@ -135,112 +126,6 @@ class sf_production_plan(models.Model):
return num
# pl_no = fields.Char(string='坯料编号', required=True, default=_get_pl_no, readonly=True)
# pl_name = fields.Char(string='坯料名称', size=64, required=True)
# material = fields.Many2one('sf.production.materials', string='材质', required=True)
# quantity = fields.Float(string='数量', required=True)
# length = fields.Float(string='长度', required=True)
# width = fields.Float(string='宽度', required=True)
# thickness = fields.Float(string='厚度', required=True)
# diameter = fields.Float(string='直径', required=True)
# plan_start_time = fields.Datetime(string='计划开始时间')
# plan_end_time = fields.Datetime(string='计划结束时间')
# state = fields.Selection([
# ('draft', '待排程'),
# ('produce', '已排程'),
# ('done', '已产出'),
# ], string='状态', copy=False, index=True, default='draft')
# customer_name = fields.Char(string='客户名称', size=64)
# order_no = fields.Char(string='订单号', size=64)
# line_no = fields.Char(string='行号', size=64)
# delivery_length = fields.Float(string='交货长度')
# delivery_width = fields.Float(string='交货宽度')
# delivery_thickness = fields.Float(string='交货厚度')
# delivery_diameter = fields.Float(string='交货直径')
# delivery_quantity = fields.Float(string='交货数量')
# delivery_date = fields.Datetime(string='交货日期', related='plan_end_time', readonly=False, store=True)
# 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了
# def do_production_schedule(self):
# """
# 排程方法
# """
# if not self.production_line_id:
# raise ValidationError("未选择生产线")
# else:
# aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)])
# workorder_time = 0
# workorder_id_list = self.production_id.workorder_ids.ids
# print(workorder_id_list)
# print(type(self.production_id.workorder_ids))
# if self.production_id.workorder_ids:
# for item in self.production_id.workorder_ids:
# if item.name == 'CNC加工':
# item.date_planned_start = self.date_planned_start
# item.date_planned_finished = item.date_planned_start + timedelta(
# minutes=self.env['mrp.routing.workcenter'].sudo().search(
# [('name', '=', 'CNC加工')]).time_cycle)
# item.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
# [('name', '=', 'CNC加工')]).time_cycle
# # print(item.id)
# sequence = workorder_id_list.index(item.id) - 1
# # print('sequence', sequence)
# # print('total', len(workorder_id_list))
# # 计算CNC加工之前工单的开始结束时间
# for i in range(sequence):
# current_workorder_id = (item.id - (i + 1))
# current_workorder_obj = self.env['mrp.workorder'].sudo().search(
# [('id', '=', current_workorder_id)])
# old_workorder_obj = self.env['mrp.workorder'].sudo().search(
# [('id', '=', (current_workorder_id + 1))])
# work_order = self.env['mrp.workorder'].sudo().search(
# [('production_id', '=', self.production_id.id), ('id', '=', current_workorder_id)])
# work_order.date_planned_finished = old_workorder_obj.date_planned_start
# work_order.date_planned_start = old_workorder_obj.date_planned_start - timedelta(
# minutes=self.env['mrp.routing.workcenter'].sudo().search(
# [('name', '=', current_workorder_obj.name)]).time_cycle)
# work_order.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
# [('name', '=', current_workorder_obj.name)]).time_cycle
# # 计算CNC加工之后工单的开始结束时间
# for j in range(len(workorder_id_list) - sequence - 2):
# current_workorder_id = (item.id + (j + 1))
# current_workorder_obj = self.env['mrp.workorder'].sudo().search(
# [('id', '=', current_workorder_id)])
# old_workorder_obj = self.env['mrp.workorder'].sudo().search(
# [('id', '=', (current_workorder_id - 1))])
# work_order = self.env['mrp.workorder'].sudo().search(
# [('production_id', '=', self.production_id.id), ('id', '=', current_workorder_id)])
# try:
# work_order.date_planned_start = old_workorder_obj.date_planned_finished
# print('work_order.data_start', work_order.date_planned_start)
# work_order.date_planned_finished = old_workorder_obj.date_planned_finished + timedelta(
# minutes=self.env['mrp.routing.workcenter'].sudo().search(
# [('name', '=', current_workorder_obj.name)]).time_cycle)
# work_order.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
# [('name', '=', current_workorder_obj.name)]).time_cycle
# except ValueError as e:
# print('时间设置失败,请检查是否为工序分配工作中心,%s' % e)
#
# current_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', item.id)])
# workorder_time += current_workorder.duration_expected
# print('workorder_time', workorder_time)
# self.date_planned_finished = self.date_planned_start + timedelta(minutes=workorder_time)
# self.state = 'done'
# self.production_id.schedule_state = '已排'
# # self.production_id.date_planned_start = self.date_planned_start
# # self.production_id.date_planned_finished = self.date_planned_finished
# else:
# raise ValidationError("未找到工单")
# # self.date_planned_finished = self.date_planned_start + timedelta(days=3)
# # self.state = 'done'
# return {
# 'name': '排程甘特图',
# 'type': 'ir.actions.act_window',
# 'res_model': 'sf.production.plan', # 要跳转的模型名称
# 'view_mode': 'gantt,tree,form', # 要显示的视图类型,可以是'form', 'tree', 'kanban', 'graph', 'calendar', 'pivot'等
# 'target': 'current', # 跳转的目标窗口,可以是'current'或'new'
# }
def do_production_schedule(self):
"""
排程方法
@@ -261,7 +146,8 @@ class sf_production_plan(models.Model):
[('name', '=', 'CNC加工')]).time_cycle
self.calculate_plan_time_before(item, workorder_id_list)
self.calculate_plan_time_after(item, workorder_id_list)
self.date_planned_start, self.date_planned_finished = item.date_planned_start, item.date_planned_finished
self.date_planned_start, self.date_planned_finished = \
item.date_planned_start, item.date_planned_finished
self.state = 'done'
self.production_id.schedule_state = '已排'
# self.production_id.date_planned_start = self.date_planned_start
@@ -348,7 +234,6 @@ class sf_production_plan(models.Model):
'bfm_process_order_list': []}
aa = self.env['ir.attachment'].search([('id', '=', 631)])
temp = self.env['product.template'].search([('id', '=', 47)])
item = aa.datas.decode('utf-8')
val = {
'model_long': 3,
'model_width': 1,