diff --git a/sf_maintenance/models/sf_maintenance.py b/sf_maintenance/models/sf_maintenance.py index 3e802c9f..9a8aecb8 100644 --- a/sf_maintenance/models/sf_maintenance.py +++ b/sf_maintenance/models/sf_maintenance.py @@ -13,7 +13,7 @@ class SfMaintenanceEquipmentCategory(models.Model): _description = '设备类别' equipment_type = fields.Selection([('机床', '机床'), ('机器人', '机器人'), ('AGV小车', 'AGV小车'), - ('检测设备', '检测设备')], string='类型', default='机床') + ('检测设备', '检测设备'), ('其他', '其他')], string='类型', default='机床') equipment_type_code = fields.Char('简写') @@ -104,18 +104,18 @@ class SfMaintenanceEquipment(models.Model): tool_diameter_max = fields.Char('刀具刀径max(mm)') tool_diameter_min = fields.Char('刀具刀径min(mm)') - def get_no(self): - partner = self.env['maintenance.equipment'].sudo().search( - [('MTcode', '!=', '')], - limit=1, - order="id desc") - if not partner: - num = "%04d" % 1 - - else: - m = int(partner.MTcode) + 1 - num = "%04d" % m - return num + # def get_no(self): + # partner = self.env['maintenance.equipment'].sudo().search( + # [('MTcode', '!=', '')], + # limit=1, + # order="id desc") + # if not partner: + # num = "%04d" % 1 + # + # else: + # m = int(partner.MTcode) + 1 + # num = "%04d" % m + # return num equipment_maintenance_standards_ids = fields.Many2many('equipment.maintenance.standards', @@ -145,7 +145,7 @@ class SfMaintenanceEquipment(models.Model): else: record.equipment_maintenance_standards_ids = False - MTcode = fields.Char("机台编码", default=get_no) + MTcode = fields.Char("机台编码") created_user = fields.Many2one('res.users', string='创建人', default=lambda self: self.env.user) equipment_type = fields.Selection([('机床', '机床'), ('机器人', '机器人'), ('AGV小车', 'AGV小车'), ('检测设备', '检测设备')], compute='_compute_category_id') @@ -178,7 +178,7 @@ class SfMaintenanceEquipment(models.Model): type_id = fields.Many2one('sf.machine_tool.type', '型号') state = fields.Selection( - [("正常", "正常"), ("故障停机", "故障停机"), ("计划维保", "计划维保"),("空闲", "空闲"),("封存(报废)", "封存(报废)")], + [("正常", "正常"), ("故障停机", "故障停机"), ("计划维保", "计划维保"), ("空闲", "空闲"), ("封存(报废)", "封存(报废)")], default='正常', string="机床状态") run_time = fields.Char('总运行时长') # 0606新增字段 @@ -230,7 +230,15 @@ class SfMaintenanceEquipment(models.Model): equipment = super(SfMaintenanceEquipment, self).create(vals) if equipment.category_id: - equipment.name = equipment.MTcode + '#' + equipment.category_id.name + equipment.name = "%s%s" % (equipment.MTcode, equipment.category_id.name) + if equipment.category_id.equipment_type == '机床': + equipment_id = self.env['maintenance.equipment.oee'].search([('equipment_id', '=', equipment.id)]) + if not equipment_id: + self.env['maintenance.equipment.oee'].sudo().create({ + 'equipment_id': equipment.id, + 'name': equipment.name, + + }) # 在创建设备之后执行一些自定义逻辑 # ... @@ -567,7 +575,6 @@ class SfMaintenanceEquipment(models.Model): 'T_tool_time': item.T_tool_time, 'C_tool_time': item.C_tool_time, 'jiancheng': item.category_id.equipment_type_code, - 'function_type': item.function_type, } machine_tool_list.append(val) # kw = machine_tool_list diff --git a/sf_maintenance/views/maintenance_views.xml b/sf_maintenance/views/maintenance_views.xml index f9d909b3..3277c20d 100644 --- a/sf_maintenance/views/maintenance_views.xml +++ b/sf_maintenance/views/maintenance_views.xml @@ -36,8 +36,7 @@ type="action" class="oe_stat_button" context="{'search_default_equipment_id': [active_id]}" - icon="fa-exchange" - attrs="{'invisible': [('state_zc', '!=', '已注册')]}"> + icon="fa-exchange"> diff --git a/sf_manufacturing/models/mrp_routing_workcenter.py b/sf_manufacturing/models/mrp_routing_workcenter.py index 8bb9733b..223ace85 100644 --- a/sf_manufacturing/models/mrp_routing_workcenter.py +++ b/sf_manufacturing/models/mrp_routing_workcenter.py @@ -22,10 +22,19 @@ 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') + def get_no(self): + international_standards = self.search( + [('code', '!=', ''), ('active', 'in', [True, False])], + limit=1, + order="id desc") + if not international_standards: + num = "%03d" % 1 + else: + m = int(international_standards.code) + 1 + num = "%03d" % m + return num - code = fields.Char('编码', default=generate_code) + code = fields.Char('编码', default=get_no) # 获得当前登陆者公司 def get_company_id(self): diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index efabad99..c8dadcb4 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -859,7 +859,7 @@ class SfMaintenanceEquipmentAndProductTemplate(models.Model): for i in range(1, number + 1): self.env['maintenance.equipment.tool'].create({ 'equipment_id': res.id, - 'code': 'T' + str(i) + 'code': "T%02d" % i }) vals.append(res) return vals[0] diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 5cb51953..c9c2ebf2 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -14,6 +14,7 @@ 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 +from odoo.exceptions import ValidationError class StockRule(models.Model): @@ -250,6 +251,22 @@ class ProductionLot(models.Model): )) return lot_names + def get_tool_generate_lot_names1(self, company, product): + """ + 采购时生成刀具物料序列号 + """ + now = datetime.now().strftime("%Y%m%d") + last_serial = self.env['stock.lot'].search( + [('company_id', '=', company.id), ('product_id', '=', product.id), ('name', 'like', now)], + limit=1, order='id DESC') + if product.cutting_tool_model_id: + if not last_serial: + return "%s-%s%03d" % (product.cutting_tool_model_id.code[:-12], now, 1) + else: + return "%s-%s%03d" % (product.cutting_tool_model_id.code[:-12], now, int(last_serial.name[-3:]) + 1) + else: + raise ValidationError('该刀具物料产品的型号字段为空,请补充完整!!!') + @api.model def _get_next_serial(self, company, product): """Return the next serial number to be attributed to the product.""" @@ -258,12 +275,13 @@ class ProductionLot(models.Model): [('company_id', '=', company.id), ('product_id', '=', product.id)], limit=1, order='id DESC') if last_serial: - return self.env['stock.lot'].generate_lot_names1(product.name, last_serial.name, 2)[ - 1] - now = datetime.now().strftime("%Y-%m-%d") - # formatted_date = now.strftime("%Y-%m-%d") + if product.categ_id.name == '刀具': + return self.env['stock.lot'].get_tool_generate_lot_names1(company, product) + else: + return self.env['stock.lot'].generate_lot_names1(product.name, last_serial.name, 2)[1] + now = datetime.now().strftime("%Y%m%d") if product.cutting_tool_model_id: - return "%s-%s-%03d" % (product.cutting_tool_model_id.code, now, 1) + return "%s-%s%03d" % (product.cutting_tool_model_id.code[:-12], now, 1) return "%s-%03d" % (product.name, 1) qr_code_image = fields.Binary(string='二维码', compute='_generate_qr_code')