Add ir.message and use custom exceptions

issue3672
This commit is contained in:
Cédric Krier
2018-12-29 14:20:29 +01:00
parent 24e039d14f
commit 86b6a609ff
3 changed files with 16 additions and 5 deletions
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data group="1">
<record model="ir.message" id="msg_opportunity_delete_cancel">
<field name="text">To delete opportunity "%(opportunity)s", you must cancel it.</field>
</record>
</data>
</tryton>
+5 -5
View File
@@ -8,8 +8,10 @@ from sql.aggregate import Max, Count, Sum
from sql.conditionals import Case, Coalesce
from sql.functions import Extract
from trytond.i18n import gettext
from trytond.model import ModelView, ModelSQL, Workflow, fields, \
sequence_ordered
from trytond.model.exceptions import AccessError
from trytond.pyson import Eval, In, If, Get, Bool
from trytond.transaction import Transaction
from trytond.pool import Pool
@@ -151,10 +153,6 @@ class SaleOpportunity(Workflow, ModelSQL, ModelView):
def __setup__(cls):
super(SaleOpportunity, cls).__setup__()
cls._order.insert(0, ('start_date', 'DESC'))
cls._error_messages.update({
'delete_cancel': ('Sale Opportunity "%s" must be cancelled '
'before deletion.'),
})
cls._transitions |= set((
('lead', 'opportunity'),
('lead', 'lost'),
@@ -304,7 +302,9 @@ class SaleOpportunity(Workflow, ModelSQL, ModelView):
cls.cancel(opportunities)
for opportunity in opportunities:
if opportunity.state != 'cancelled':
cls.raise_user_error('delete_cancel', opportunity.rec_name)
raise AccessError(
gettext('sale_opportunity.msg_opportunity_delete_cancel',
opportunity=opportunity.rec_name))
super(SaleOpportunity, cls).delete(opportunities)
@classmethod
+1
View File
@@ -13,3 +13,4 @@ xml:
opportunity.xml
party.xml
configuration.xml
message.xml