diff --git a/exceptions.py b/exceptions.py new file mode 100644 index 0000000000..f527e01c69 --- /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 WorkValidationError(ValidationError): + pass diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..89af916aac --- /dev/null +++ b/message.xml @@ -0,0 +1,16 @@ + + + + + + To open work "%(child)s", you must open its parent "%(parent)s". + + + To close work "%(parent)s", you must close its child "%(child)s". + + + You cannot erase party "%(party)s" while they have opened projects with company "%(company)s". + + + diff --git a/party.py b/party.py index eb0b678645..0e25edee32 100644 --- a/party.py +++ b/party.py @@ -1,7 +1,10 @@ # 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.i18n import gettext from trytond.pool import PoolMeta, Pool +from trytond.modules.party.exceptions import EraseError + __all__ = ['PartyReplace', 'PartyErase'] @@ -18,16 +21,6 @@ class PartyReplace(metaclass=PoolMeta): class PartyErase(metaclass=PoolMeta): __name__ = 'party.erase' - @classmethod - def __setup__(cls): - super(PartyErase, cls).__setup__() - cls._error_messages.update({ - 'opened_project': ( - 'The party "%(party)s" can not be erased ' - 'because he has opened projects ' - 'for the company "%(company)s".'), - }) - def check_erase_company(self, party, company): pool = Pool() Work = pool.get('project.work') @@ -38,7 +31,7 @@ class PartyErase(metaclass=PoolMeta): ('state', '!=', 'done'), ]) if works: - self.raise_user_error('opened_project', { - 'party': party.rec_name, - 'company': company.rec_name, - }) + raise EraseError( + gettext('project.msg_erase_party_opened_project', + party=party.rec_name, + company=company.rec_name)) diff --git a/tryton.cfg b/tryton.cfg index 9ca1d55498..edfdfbaa13 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -9,3 +9,4 @@ xml: project.xml work.xml timesheet.xml + message.xml diff --git a/work.py b/work.py index 5d196c7be6..3fcaf7f00b 100644 --- a/work.py +++ b/work.py @@ -5,12 +5,15 @@ import datetime from sql import Null +from trytond.i18n import gettext from trytond.model import ModelView, ModelSQL, fields, sequence_ordered, tree from trytond.pyson import Eval from trytond.transaction import Transaction from trytond.pool import Pool from trytond.tools import reduce_ids, grouped_slice +from .exceptions import WorkValidationError + __all__ = ['Work'] @@ -195,17 +198,6 @@ class Work(sequence_ordered(), tree(separator='\\'), ModelSQL, ModelView): where=timesheet.id == work_id)) table_project_work.drop_column('work') - @classmethod - def __setup__(cls): - super(Work, cls).__setup__() - cls._error_messages.update({ - 'invalid_parent_state': ('Work "%(child)s" can not be opened ' - 'because its parent work "%(parent)s" is already done.'), - 'invalid_children_state': ('Work "%(parent)s" can not be ' - 'done because its child work "%(child)s" is still ' - 'opened.'), - }) - @classmethod def index_set_field(cls, name): index = super(Work, cls).index_set_field(name) @@ -222,17 +214,17 @@ class Work(sequence_ordered(), tree(separator='\\'), ModelSQL, ModelView): def check_state(self): if (self.state == 'opened' and (self.parent and self.parent.state == 'done')): - self.raise_user_error('invalid_parent_state', { - 'child': self.rec_name, - 'parent': self.parent.rec_name, - }) + raise WorkValidationError( + gettext('project.msg_work_invalid_parent_state', + child=self.rec_name, + parent=self.parent.rec_name)) if self.state == 'done': for child in self.children: if child.state == 'opened': - self.raise_user_error('invalid_children_state', { - 'parent': self.rec_name, - 'child': child.rec_name, - }) + raise WorkValidationError( + gettext('project.msg_work_invalid_children_state', + parent=self.rec_name, + child=child.rec_name)) @property def effort_hours(self):