minor fix can not delete if record have move

This commit is contained in:
wilsongomez 2022-05-02 17:28:58 -05:00
parent 761405568d
commit eef662f29d
3 changed files with 24 additions and 1 deletions

View File

@ -12,6 +12,9 @@ class ImportDataEmployeeError(ValidationError):
class LiquidationEmployeeError(UserError):
pass
class LiquidationDeleteError(UserError):
pass
class LiquidationMoveError(UserError):
pass

View File

@ -10,7 +10,7 @@ from trytond.transaction import Transaction
from trytond.i18n import gettext
from .exceptions import (
LiquidationEmployeeError, MissingSecuenceLiquidation,
LiquidationMoveError, WageTypeConceptError
LiquidationMoveError, WageTypeConceptError, LiquidationDeleteError
)
STATES = {'readonly': (Eval('state') != 'draft')}
@ -456,6 +456,19 @@ class Liquidation(Workflow, ModelSQL, ModelView):
])
return lines
@classmethod
def delete(cls, records):
# Cancel before delete
cls.cancel(records)
for liquidation in records:
if liquidation.state != 'cancel':
raise LiquidationDeleteError(
gettext('staff_payroll_co.msg_delete_cancel', liquidation=liquidation.rec_name))
if liquidation.move:
raise LiquidationDeleteError(
gettext('staff_payroll_co.msg_existing_move', liquidation=liquidation.rec_name))
super(Payroll, cls).delete(records)
def set_liquidation_lines(self):
pool = Pool()
Payroll = pool.get('staff.payroll')

View File

@ -58,5 +58,12 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_missing_party">
<field name="text">Missing party in mandatory wage "%(wage)s" for employee "%(employee)s"</field>
</record>
<record model="ir.message" id="msg_delete_cancel">
<field name="text">Liquidation "%(liquidation)s" must be cancelled before deletion.</field>
</record>
<record model="ir.message" id="msg_existing_move">
<field name="text">Liquidation "%(liquidation)s" has a move, must be deleted before deletion.</field>
</record>
</data>
</tryton>