Files
jikimo_sf/sf_plan_management/models/base.py

47 lines
2.5 KiB
Python

from odoo import models, fields, api
from odoo.exceptions import UserError
class ProcedureEquipmentResourceSetting(models.Model):
_name = 'sf.procedure.equipment.resource.setting'
_description = '产线设备资源设置'
name = fields.Many2one('sf.production.line', string='生产线', required=True)
work_center_name_id = fields.Many2one('mrp.workcenter', string='工作中心名称')
equipment_name_id = fields.Many2one('maintenance.equipment', string='设备名称', readonly=True, search=True,
compute='_compute_equipment_name_id')
equipment_code = fields.Char(string='机台号', readonly=True, related='equipment_name_id.code')
brand_id = fields.Many2one('sf.machine.brand', string='品牌', readonly=True, related='equipment_name_id.brand_id')
type_id = fields.Many2one('sf.machine_tool.type', string='型号', readonly=True, related='equipment_name_id.type_id')
status = fields.Selection(string='设备状态', readonly=True, related='equipment_name_id.state')
# todo 传入工序数据
working_procedure = fields.Char(string='工序', readonly=True)
production_capacity = fields.Float(string='产能', required=True, digits=(4, 1))
working_calendar_id = fields.Many2one('sf.work.log.setting', string='工作日历')
working_shift_id = fields.Many2many('sf.working.shift', string='班次', readonly=True,
compute='_compute_working_shift_id')
create_time = fields.Datetime(string='新增时间', default=lambda self: fields.Datetime.now(), readonly=True)
participate_in_scheduling = fields.Boolean(string='参与排程', default=True)
@api.depends('work_center_name_id')
def _compute_equipment_name_id(self):
for record in self:
if record.work_center_name_id:
record.equipment_name_id = record.work_center_name_id.equipment_id
else:
record.equipment_name_id = None
@api.constrains('production_capacity')
def _check_production_capacity(self):
for record in self:
if record.production_capacity < 0:
raise UserError("产能不能为负!")
@api.depends('working_calendar_id')
def _compute_working_shift_id(self):
for record in self:
if record.working_calendar_id:
record.working_shift_id = record.working_calendar_id.working_shift_ids
else:
record.working_shift_id = None