trytonpsk-staff/employee.py

83 lines
2.7 KiB
Python
Raw Normal View History

2020-04-16 00:27:15 +02:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import fields, Unique
from trytond.pool import PoolMeta, Pool
from trytond.transaction import Transaction
2021-01-19 18:15:29 +01:00
class Employee(metaclass=PoolMeta):
2020-04-16 00:27:15 +02:00
__name__ = 'company.employee'
active = fields.Boolean('Active')
code = fields.Char('Code', size=None, select=True)
salary = fields.Function(fields.Numeric('Salary', digits=(16, 2),
2020-11-04 01:47:40 +01:00
help='Salary monthly of person',
depends=['contract'], readonly=True), 'get_salary')
2020-04-16 00:27:15 +02:00
contract = fields.Function(fields.Many2One('staff.contract',
2021-09-14 16:01:58 +02:00
'Contract'), 'get_contract', searcher='search_contract')
2020-04-16 00:27:15 +02:00
position = fields.Function(fields.Many2One('staff.position', 'Position'), 'get_position')
curses = fields.Text('Curses')
career = fields.Text('Career')
contracting_state = fields.Selection([
('', ''),
('aspirant', 'Aspirant'),
('rejected', 'Rejected'),
('active', 'Active'),
('finished', 'Finished'),
], 'Contracting State')
@classmethod
def __setup__(cls):
super(Employee, cls).__setup__()
table = cls.__table__()
2021-01-19 18:15:29 +01:00
cls._sql_constraints += [(
'party_uniq', Unique(table, table.party), 'Employee already exists!'
)]
2020-04-16 00:27:15 +02:00
@classmethod
def __register__(cls, module_name):
super(Employee, cls).__register__(module_name)
cursor = Transaction().connection.cursor()
sql_table = cls.__table__()
2021-01-19 18:15:29 +01:00
# Migration: Rename in_process to aspirant into contracting_state
2020-04-16 00:27:15 +02:00
cursor.execute(*sql_table.update(
columns=[sql_table.contracting_state],
values=['aspirant'],
where=(sql_table.contracting_state == 'in_process')
2021-01-19 18:15:29 +01:00
))
2020-04-16 00:27:15 +02:00
@staticmethod
def default_active():
return True
@staticmethod
def default_company():
return Transaction().context.get('company')
def get_position(self, name=None):
if self.contract and self.contract.position:
return self.contract.position.id
def get_contract(self, name=None):
Contract = Pool().get('staff.contract')
contracts = Contract.search([
('employee', '=', self.id),
('state', '=', 'active'),
])
if contracts:
return contracts[0].id
2021-09-14 16:01:58 +02:00
@classmethod
def search_contract(cls, name, clause):
return
2020-04-16 00:27:15 +02:00
def get_salary(self, name=None):
if self.contract:
2021-06-02 19:26:32 +02:00
return self.contract.salary
2020-04-16 00:27:15 +02:00
@fields.depends('contract')
def on_change_with_salary(self):
if self.contract:
2021-01-19 18:15:29 +01:00
self.salary = self.contract.salary