add register for migration columns in wage type and mandatory wages

This commit is contained in:
Camilo Sarmiento 2020-05-28 09:03:30 -05:00
parent 268fdb95e5
commit 47657f4225
3 changed files with 35 additions and 2 deletions

View File

@ -15,6 +15,7 @@ def register():
Pool.register(
uvt.UvtWithholding,
employee.Employee,
employee.MandatoryWage,
position.Position,
wage_type.WageType,
payroll.Payroll,

View File

@ -2,14 +2,14 @@
#this repository contains the full copyright notices and license terms.
from trytond.model import fields
from trytond.pool import PoolMeta, Pool
from trytond.transaction import Transaction
from decimal import Decimal
from datetime import datetime, date, timedelta
__all__ = ['Employee']
class Employee:
__metaclass__ = PoolMeta
class Employee(metaclass=PoolMeta):
__name__ = 'company.employee'
party_health = fields.Function(fields.Many2One('party.party', 'Party Health'),
'get_party_concept')
@ -213,3 +213,28 @@ class Employee:
def get_party_bank(self, name=None):
return None
class MandatoryWage(metaclass=PoolMeta):
__name__ = 'staff.payroll.mandatory_wage'
@classmethod
def __register__(cls, module_name):
super(MandatoryWage, cls).__register__(module_name)
cursor = Transaction().connection.cursor()
sql_table = cls.__table__()
string_query = "SELECT EXISTS(" \
" SELECT column_name FROM information_schema.columns" \
" WHERE table_schema='public'" \
" and table_name='staff_payroll_mandatory_wage'" \
" and column_name='defect_amount')"
cursor.execute(string_query)
res = cursor.fetchall()
if res and res[0][0]:
# try:
cursor.execute(*sql_table.update(
columns=[sql_table.fix_amount],
values=[sql_table.defect_amount]))
cursor.execute('ALTER TABLE staff_payroll_mandatory_wage DROP COLUMN IF EXISTS defect_amount')
# cursor.execute('UPDATE staff_payroll_mandatory_wage set fix_amount=defect_amount')
# except:
# print('# WARNING: The column defect_amount not exists')

View File

@ -3,6 +3,7 @@
from trytond.pool import PoolMeta, Pool
from trytond.model import fields
from trytond.pyson import Eval
from trytond.transaction import Transaction
__all__ = ['WageType']
@ -63,6 +64,12 @@ class WageType(metaclass=PoolMeta):
if new_sel not in cls.type_concept.selection:
cls.type_concept.selection.extend(new_sel)
@classmethod
def __register__(cls, module_name):
super(WageType, cls).__register__(module_name)
cursor = Transaction().connection.cursor()
cursor.execute('ALTER TABLE staff_wage_type DROP COLUMN IF EXISTS amount_required')
# def validate_minimum_amount(self, name):
# config = Pool().get('staff.configuration')(1)
# if config: