kalenislims/lims/department.py

49 lines
1.5 KiB
Python
Raw Normal View History

2017-10-08 02:23:22 +02:00
# -*- coding: utf-8 -*-
# This file is part of lims module for Tryton.
2017-10-08 02:23:22 +02:00
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields
2019-07-23 23:27:33 +02:00
from trytond.exceptions import UserError
from trytond.i18n import gettext
2017-10-08 02:23:22 +02:00
class Department(ModelSQL, ModelView):
'Department'
__name__ = 'company.department'
code = fields.Char('Code', required=True)
name = fields.Char('Name', required=True)
default_location = fields.Many2One('stock.location', 'Default Location',
domain=[('type', '=', 'storage')])
class UserDepartment(ModelSQL, ModelView):
'User Department'
__name__ = 'user.department'
user = fields.Many2One('res.user', 'User', required=True)
department = fields.Many2One('company.department', 'Department',
required=True)
default = fields.Boolean('By default')
@staticmethod
def default_default():
return False
@classmethod
def validate(cls, user_departments):
2020-08-06 19:52:36 +02:00
super().validate(user_departments)
2017-10-08 02:23:22 +02:00
for ud in user_departments:
ud.check_default()
def check_default(self):
if self.default:
user_departments = self.search([
('user', '=', self.user.id),
('default', '=', True),
('id', '!=', self.id),
])
if user_departments:
2019-07-23 23:27:33 +02:00
raise UserError(gettext('lims.msg_default_department'))