diff --git a/__init__.py b/__init__.py
index 1fb71e4..cee4e71 100644
--- a/__init__.py
+++ b/__init__.py
@@ -2,19 +2,19 @@
# this repository contains the full copyright notices and license terms.
from trytond.pool import Pool
-from .position import Position
-from .employee import Employee
-from .holidays import Holidays
-from .contract import StaffContract
-from .configuration import Configuration, StaffConfigurationSequence
+from . import position
+from . import employee
+from . import holidays
+from . import contract
+from . import configuration
def register():
Pool.register(
- Holidays,
- Position,
- Employee,
- StaffContract,
- Configuration,
- StaffConfigurationSequence,
+ holidays.Holidays,
+ position.Position,
+ employee.Employee,
+ contract.StaffContract,
+ configuration.Configuration,
+ configuration.StaffConfigurationSequence,
module='staff', type_='model')
diff --git a/configuration.py b/configuration.py
index 4d2bcdd..48de0fd 100644
--- a/configuration.py
+++ b/configuration.py
@@ -3,13 +3,11 @@
from trytond import backend
from trytond.model import ModelView, ModelSQL, ModelSingleton, fields
from trytond.pool import Pool
-from trytond.pyson import Eval
+from trytond.pyson import Eval, Id
from trytond.tools.multivalue import migrate_property
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
-__all__ = ['Configuration', 'StaffConfigurationSequence']
-
def default_func(field_name):
@classmethod
@@ -25,7 +23,8 @@ class Configuration(
'Staff Configuration'
__name__ = 'staff.configuration'
staff_contract_sequence = fields.Many2One('ir.sequence', 'Contract Sequence',
- required=True, domain=[('code', '=', 'staff.contract')])
+ required=True, domain=[('sequence_type', '=',
+ Id('staff', 'sequence_type_staff_contract')), ])
default_staff_contract_sequence = default_func('staff_contract_sequence')
@@ -44,15 +43,13 @@ class StaffConfigurationSequence(ModelSQL, CompanyValueMixin):
'ir.sequence', "Staff Contract Sequence", required=True,
domain=[
('company', 'in', [Eval('company', -1), None]),
- ('code', '=', 'staff.contract'),
+ ('sequence_type', '=', Id('staff', 'sequence_type_staff_contract'))
],
depends=['company'])
@classmethod
def __register__(cls, module_name):
- TableHandler = backend.get('TableHandler')
- exist = TableHandler.table_exist(cls._table)
-
+ exist = backend.TableHandler.table_exist(cls._table)
super(StaffConfigurationSequence, cls).__register__(module_name)
if not exist:
diff --git a/contract.py b/contract.py
index 295d518..09dfd06 100644
--- a/contract.py
+++ b/contract.py
@@ -3,10 +3,12 @@
from trytond.model import ModelView, Workflow, ModelSQL, fields
from trytond.pyson import Eval
from trytond.pool import Pool
+from trytond.i18n import gettext
+from trytond.model.exceptions import AccessError
from trytond.transaction import Transaction
+from .exceptions import (StaffContractError)
from sql import Null
-__all__ = ['StaffContract']
STATES = {'readonly': (Eval('state') != 'draft')}
@@ -67,11 +69,6 @@ class StaffContract(Workflow, ModelSQL, ModelView):
'invisible': Eval('state') != 'active',
},
})
- cls._error_messages.update({
- 'employee_with_contract_current': ('The employee %s already has a contract in draft or active!'),
- 'missing_contract_sequence': ('The contract sequence is missing on configuration!'),
- 'finish_contract_out_date': ('You can not to finish a contract with end date on future!'),
- })
# @classmethod
# def __register__(cls, module_name):
@@ -144,22 +141,21 @@ class StaffContract(Workflow, ModelSQL, ModelView):
def _check_finish_date(self):
today = Pool().get('ir.date').today()
if self.end_date and self.end_date > today:
- self.raise_user_error('finish_contract_out_date')
+ raise StaffContractError(gettext('finish_contract_out_date'))
def set_number(self):
'''
Fill the reference field with the request sequence
'''
pool = Pool()
- Sequence = pool.get('ir.sequence')
Config = pool.get('staff.configuration')
config = Config(1)
if self.number:
return
if not config.staff_contract_sequence:
- self.raise_user_error('missing_contract_sequence')
- number = Sequence.get_id(config.staff_contract_sequence.id)
+ raise StaffContractError(gettext('missing_contract_sequence'))
+ number = config.staff_contract_sequence.get()
self.write([self], {'number': number})
@classmethod
@@ -171,6 +167,6 @@ class StaffContract(Workflow, ModelSQL, ModelView):
('state', 'in', ('active', 'draft')),
])
if contracts_current:
- cls.raise_user_error('employee_with_contract_current',
- contracts_current[0].employee.rec_name)
+ raise AccessError(gettext('employee_with_contract_current',
+ contract=contracts_current[0].employee.rec_name))
return super(StaffContract, cls).create(vlist)
diff --git a/contract.xml b/contract.xml
index c2b1875..d359899 100644
--- a/contract.xml
+++ b/contract.xml
@@ -34,11 +34,10 @@ this repository contains the full copyright notices and license terms. -->
Staff Contract
- staff.contract
Contracts
- staff.contract
+
diff --git a/employee.py b/employee.py
index bcbd319..f69ca9d 100644
--- a/employee.py
+++ b/employee.py
@@ -4,8 +4,6 @@ from trytond.model import fields, Unique
from trytond.pool import PoolMeta, Pool
from trytond.transaction import Transaction
-__all__ = ['Employee']
-
class Employee(metaclass=PoolMeta):
__name__ = 'company.employee'
@@ -72,7 +70,7 @@ class Employee(metaclass=PoolMeta):
def get_salary(self, name=None):
if self.contract:
- return self.contract.last_salary
+ return self.contract.salary
@fields.depends('contract')
def on_change_with_salary(self):
diff --git a/exceptions.py b/exceptions.py
new file mode 100644
index 0000000..300de19
--- /dev/null
+++ b/exceptions.py
@@ -0,0 +1,8 @@
+# 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.exceptions import ValidationError
+
+
+class StaffContractError(ValidationError):
+ pass
diff --git a/holidays.py b/holidays.py
index 4e5bda9..9156c3f 100644
--- a/holidays.py
+++ b/holidays.py
@@ -3,8 +3,6 @@
#from datetime import datetime
from trytond.model import ModelView, ModelSQL, fields
-__all__ = ['Holidays']
-
class Holidays(ModelSQL, ModelView):
"Holidays"
diff --git a/message.xml b/message.xml
new file mode 100644
index 0000000..67868c7
--- /dev/null
+++ b/message.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+ The employee "%(contract)" already has a contract in draft or active!.
+
+
+ The contract sequence is missing on configuration!
+
+
+ You can not to finish a contract with end date on future!
+
+
+
+
diff --git a/position.py b/position.py
index 12ac343..5375564 100644
--- a/position.py
+++ b/position.py
@@ -2,8 +2,6 @@
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields
-__all__ = ['Position']
-
class Position(ModelSQL, ModelView):
'Position'
diff --git a/staff.xml b/staff.xml
index ac5a3f6..8d37651 100644
--- a/staff.xml
+++ b/staff.xml
@@ -18,14 +18,6 @@ this repository contains the full copyright notices and license terms. -->
-
-
-
-
-
-
-
-
tryton-staff
diff --git a/tryton.cfg b/tryton.cfg
index 0c3204e..a8b2b8e 100644
--- a/tryton.cfg
+++ b/tryton.cfg
@@ -1,5 +1,5 @@
[tryton]
-version=5.0.0
+version=6.0.0
depends:
ir
party