changeset 96fa0f783a72 in modules/sale_opportunity:default
details:
https://hg.tryton.org/modules/sale_opportunity?cmd=changeset;node=96fa0f783a72
description:
Add ir.message and use custom exceptions
issue3672
diffstat:
message.xml | 10 ++++++++++
opportunity.py | 10 +++++-----
tryton.cfg | 1 +
3 files changed, 16 insertions(+), 5 deletions(-)
diffs (58 lines):
diff -r 0c21b57afb13 -r 96fa0f783a72 message.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml Sat Dec 29 14:20:29 2018 +0100
@@ -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>
diff -r 0c21b57afb13 -r 96fa0f783a72 opportunity.py
--- a/opportunity.py Fri Oct 05 17:26:48 2018 +0200
+++ b/opportunity.py Sat Dec 29 14:20:29 2018 +0100
@@ -8,8 +8,10 @@
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 @@
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 @@
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
diff -r 0c21b57afb13 -r 96fa0f783a72 tryton.cfg
--- a/tryton.cfg Fri Oct 05 17:26:48 2018 +0200
+++ b/tryton.cfg Sat Dec 29 14:20:29 2018 +0100
@@ -13,3 +13,4 @@
opportunity.xml
party.xml
configuration.xml
+ message.xml