Add ir.message and use custom exceptions
issue3672
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
# 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.exceptions import UserError
|
||||
from trytond.model.exceptions import ValidationError
|
||||
|
||||
|
||||
class InvoiceError(UserError):
|
||||
pass
|
||||
|
||||
|
||||
class RecurrenceRuleValidationError(ValidationError):
|
||||
pass
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<?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_consumption_modify_invoiced">
|
||||
<field name="text">You cannot modify invoiced consumption "%(consumption)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_consumption_delete_invoiced">
|
||||
<field name="text">You cannot delete invoiced consumption "%(consumption)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_consumption_invoice_missing_account_revenue">
|
||||
<field name="text">To invoice consumptions you must define an account revenue for product "%(product)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_erase_party_pending_subscription">
|
||||
<field name="text">You cannot erase party "%(party)s" while they have pending subscriptions with company "%(company)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_recurrence_rule_invalid_by">
|
||||
<field name="text">Invalid "%(field)s" "%(value)s" in recurence rule "%(recurrence_rule)s" with exception "%(exception)s".</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -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({
|
||||
'pending_subscription': (
|
||||
'The party "%(party)s" can not be erased '
|
||||
'because he has pending subscriptions '
|
||||
'for the company "%(company)s".'),
|
||||
})
|
||||
|
||||
def check_erase_company(self, party, company):
|
||||
pool = Pool()
|
||||
Subscription = pool.get('sale.subscription')
|
||||
@@ -38,7 +31,8 @@ class PartyErase(metaclass=PoolMeta):
|
||||
('state', 'not in', ['closed', 'canceled']),
|
||||
])
|
||||
if subscriptions:
|
||||
self.raise_user_error('pending_subscription', {
|
||||
'party': party.rec_name,
|
||||
'company': company.rec_name,
|
||||
})
|
||||
raise EraseError(
|
||||
gettext('sale_subscription'
|
||||
'.msg_erase_party_pending_subscription',
|
||||
party=party.rec_name,
|
||||
company=company.rec_name))
|
||||
|
||||
+10
-22
@@ -4,9 +4,12 @@ from dateutil.rrule import MO, TU, WE, TH, FR, SA, SU
|
||||
from dateutil.rrule import YEARLY, MONTHLY, WEEKLY, DAILY
|
||||
from dateutil.rrule import rrule, rruleset
|
||||
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
from .exceptions import RecurrenceRuleValidationError
|
||||
|
||||
__all__ = ['RecurrenceRuleSet', 'RecurrenceRule']
|
||||
WEEKDAYS = {
|
||||
'MO': MO,
|
||||
@@ -100,24 +103,6 @@ class RecurrenceRule(ModelSQL, ModelView):
|
||||
|
||||
exclusive = fields.Boolean("Exclusive")
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(RecurrenceRule, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'invalid_byweekday': (
|
||||
'"By Week Day" (%(byweekday)s) is not valid.'),
|
||||
'invalid_bymonthday': (
|
||||
'"By Month Day" (%(bymonthday)s) is not valid.'),
|
||||
'invalid_byyearday': (
|
||||
'"By Year Day" (%(byyearday)s) is not valid.'),
|
||||
'invalid_byweekno': (
|
||||
'"By Week Number" (%(byweekno)s) is not valid.'),
|
||||
'invalid_bymonth': (
|
||||
'"By Month" (%(bymonth)s) is not valid.'),
|
||||
'invalid_bysetpos': (
|
||||
'"By Position" (%(bysetpos)s) is not valid.'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def default_interval(cls):
|
||||
return 1
|
||||
@@ -214,7 +199,10 @@ class RecurrenceRule(ModelSQL, ModelView):
|
||||
def check_by(self, name):
|
||||
try:
|
||||
getattr(self, '_%s' % name)
|
||||
except ValueError:
|
||||
self.raise_user_error('invalid_%s' % name, {
|
||||
name: getattr(self, name),
|
||||
})
|
||||
except ValueError as exception:
|
||||
raise RecurrenceRuleValidationError(
|
||||
gettext('sale_subscription.msg_recurrence_rule_invalid_by',
|
||||
value=getattr(self, name),
|
||||
recurrence_rule=self.rec_name,
|
||||
exception=exception,
|
||||
**self._get_error_args(name))) from exception
|
||||
|
||||
+20
-17
@@ -8,8 +8,10 @@ from sql import operators, Literal, Null
|
||||
from sql.conditionals import Coalesce
|
||||
|
||||
from trytond import backend
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import ModelSQL, ModelView, Workflow, fields, \
|
||||
sequence_ordered
|
||||
from trytond.model.exceptions import AccessError
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval, If, Bool
|
||||
from trytond.transaction import Transaction
|
||||
@@ -17,6 +19,7 @@ from trytond.wizard import Wizard, StateView, StateAction, StateTransition, \
|
||||
Button
|
||||
|
||||
from trytond.modules.product import price_digits
|
||||
from .exceptions import InvoiceError
|
||||
|
||||
__all__ = ['Subscription', 'Line', 'LineConsumption',
|
||||
'CreateLineConsumption', 'CreateLineConsumptionStart',
|
||||
@@ -726,14 +729,6 @@ class LineConsumption(ModelSQL, ModelView):
|
||||
def __setup__(cls):
|
||||
super(LineConsumption, cls).__setup__()
|
||||
cls._order.insert(0, ('date', 'DESC'))
|
||||
cls._error_messages.update({
|
||||
'modify_invoiced_consumption': (
|
||||
"You can not modify invoiced consumption."),
|
||||
'delete_invoiced_consumption': (
|
||||
"You can not delete invoiced consumption."),
|
||||
'missing_account_revenue': ('Product "%(product)s" '
|
||||
'misses a revenue account.'),
|
||||
})
|
||||
|
||||
@fields.depends('line')
|
||||
def on_change_with_unit_digits(self, name=None):
|
||||
@@ -752,16 +747,23 @@ class LineConsumption(ModelSQL, ModelView):
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
if any(c.invoice_line
|
||||
for consumptions in args[::2]
|
||||
for c in consumptions):
|
||||
cls.raise_user_error('modify_invoiced_consumption')
|
||||
for consumptions in args[::2]:
|
||||
for consumption in consumptions:
|
||||
if consumption.invoice_line:
|
||||
raise AccessError(
|
||||
gettext('sale_subscription'
|
||||
'.msg_consumption_modify_invoiced',
|
||||
consumption=consumption.rec_name))
|
||||
super(LineConsumption, cls).write(*args)
|
||||
|
||||
@classmethod
|
||||
def delete(cls, consumptions):
|
||||
if any(c.invoice_line for c in consumptions):
|
||||
cls.raise_user_error('delete_invoiced_consumption')
|
||||
for consumption in consumptions:
|
||||
if consumption.invoice_line:
|
||||
raise AccessError(
|
||||
gettext('sale_subscription'
|
||||
'.msg_consumption_modify_invoiced',
|
||||
consumption=consumption.rec_name))
|
||||
super(LineConsumption, cls).delete(consumptions)
|
||||
|
||||
@classmethod
|
||||
@@ -782,9 +784,10 @@ class LineConsumption(ModelSQL, ModelView):
|
||||
|
||||
line.account = line.product.account_revenue_used
|
||||
if not line.account:
|
||||
cls.raise_user_error('missing_account_revenue', {
|
||||
'product': line.product.rec_name,
|
||||
})
|
||||
raise InvoiceError(
|
||||
gettext('sale_subscription'
|
||||
'.msg_consumption_invoice_missing_account_revenue',
|
||||
product=line.product.rec_name))
|
||||
|
||||
taxes = []
|
||||
pattern = line._get_tax_rule_pattern()
|
||||
|
||||
@@ -14,3 +14,4 @@ xml:
|
||||
recurrence.xml
|
||||
service.xml
|
||||
subscription.xml
|
||||
message.xml
|
||||
|
||||
Reference in New Issue
Block a user