minor fix

This commit is contained in:
wilson gomez 2021-07-13 15:35:06 -05:00
parent 788a200eda
commit 4002bae498
1 changed files with 26 additions and 25 deletions

View File

@ -7,11 +7,18 @@ from trytond.i18n import gettext
from trytond.model.exceptions import AccessError
from trytond.transaction import Transaction
from .exceptions import (StaffContractError)
from trytond import backend
from trytond.tools.multivalue import migrate_property
from sql import Null
STATES = {'readonly': (Eval('state') != 'draft')}
PAYMENT_TERM = [
('', ''),
('1', 'Cash')
]
class StaffContract(Workflow, ModelSQL, ModelView):
"Staff Contract"
@ -44,7 +51,7 @@ class StaffContract(Workflow, ModelSQL, ModelView):
('active', 'Active'),
('finished', 'Finished'),
], 'State', readonly=True, select=True)
payment_term = fields.Char('Payment Term', states=STATES)
payment_term = fields.Selection(PAYMENT_TERM, 'Payment Term', states=STATES)
comment = fields.Text("Comment", states=STATES)
position = fields.Many2One('staff.position', 'Position',
select=True)
@ -70,30 +77,20 @@ class StaffContract(Workflow, ModelSQL, ModelView):
},
})
# @classmethod
# def __register__(cls, module_name):
# super(StaffContract, cls).__register__(module_name)
# pool = Pool()
# Employee = pool.get('company.employee')
# cursor = Transaction().connection.cursor()
# sql_table = cls.__table__()
# employee = Employee.__table__()
#
# # Migration:
# # - Migration position from employee into contract
# sub_query = employee.select(
# employee.id, employee.position,
# where=(employee.position != Null)
# )
# cursor.execute(*sub_query)
#
# for employee_id, position in cursor.fetchall():
# cursor.execute(*sql_table.update(
# columns=[sql_table.position],
# values=[position],
# where=(sql_table.employee == employee_id)
# & (sql_table.position == Null)
# ))
@classmethod
def __register__(cls, module_name):
exist = backend.TableHandler.table_exist(cls._table)
super(StaffContract, cls).__register__(module_name)
if not exist:
cls._migrate_property([], [], [])
@classmethod
def _migrate_property(cls, field_names, value_names, fields):
field_names.append('payment_term')
migrate_property(
'staff.contract', field_names, cls, value_names,
fields=fields)
@staticmethod
def default_company():
@ -107,6 +104,10 @@ class StaffContract(Workflow, ModelSQL, ModelView):
def default_kind():
return 'job'
@staticmethod
def default_payment_term():
return '1'
@classmethod
def search_rec_name(cls, name, clause):
if clause[1].startswith('!') or clause[1].startswith('not '):