Use new raise_user_error function
This commit is contained in:
1 parent
5535f8e1f6
commit
cd8daf87a4
4 files changed
+108
-50
No files matched your search
+31
-12
@@ -1,8 +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.
|
||||
'Fiscal Year'
|
||||
|
||||
from trytond.osv import fields, OSV, ExceptORM
|
||||
from trytond.wizard import Wizard, WizardOSV, ExceptWizard
|
||||
from trytond.osv import fields, OSV
|
||||
from trytond.wizard import Wizard, WizardOSV
|
||||
import mx.DateTime
|
||||
import datetime
|
||||
from decimal import Decimal
|
||||
@@ -46,6 +46,11 @@ class FiscalYear(OSV):
|
||||
'per fiscal year!', ['post_move_sequence']),
|
||||
]
|
||||
self._order.insert(0, ('start_date', 'ASC'))
|
||||
self._error_messages.update({
|
||||
'change_post_move_sequence': 'You can not change ' \
|
||||
'the post move sequence',
|
||||
'no_fiscalyear_date': 'No fiscal year defined for this date!',
|
||||
})
|
||||
|
||||
def default_state(self, cursor, user, context=None):
|
||||
return 'open'
|
||||
@@ -92,8 +97,8 @@ class FiscalYear(OSV):
|
||||
if fiscalyear.post_move_sequence and \
|
||||
fiscalyear.post_move_sequence.id != \
|
||||
vals['post_move_sequence']:
|
||||
raise ExceptORM('UserError', 'You can not change ' \
|
||||
'the post move sequence')
|
||||
self.raise_user_error(cursor, 'change_post_move_sequence',
|
||||
context=context)
|
||||
return super(FiscalYear, self).write(cursor, user, ids, vals,
|
||||
context=context)
|
||||
|
||||
@@ -151,7 +156,8 @@ class FiscalYear(OSV):
|
||||
], order=[('start_date', 'DESC')], limit=1, context=context)
|
||||
if not ids:
|
||||
if exception:
|
||||
raise ExceptORM('Error', 'No fiscal year defined for this date!')
|
||||
self.raise_user_error(cursor, 'no_fiscalyear_date',
|
||||
context=context)
|
||||
else:
|
||||
return False
|
||||
return ids[0]
|
||||
@@ -220,6 +226,17 @@ class CloseFiscalYear(Wizard):
|
||||
},
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
super(CloseFiscalYear, self).__init__()
|
||||
self._error_messages.update({
|
||||
'diff_fiscalyear': 'The fiscal years must be different!',
|
||||
'period_in_fiscalyear': 'The period must be ' \
|
||||
'in the selected fiscal year!',
|
||||
'centralised_journal': 'The journal must be centralised!',
|
||||
'journal_default_debit_credit_account': 'The journal must have ' \
|
||||
'default debit/credit accounts!',
|
||||
})
|
||||
|
||||
def _process_account(self, cursor, user, account, period, journal, name,
|
||||
fiscalyear_id, period_ids, context=None):
|
||||
'''
|
||||
@@ -308,23 +325,25 @@ class CloseFiscalYear(Wizard):
|
||||
account_obj = self.pool.get('account.account')
|
||||
|
||||
if data['form']['close_fiscalyear'] == data['form']['fiscalyear']:
|
||||
raise ExceptWizard('UserError',
|
||||
'The fiscal years must be different!')
|
||||
self.raise_user_error(cursor, 'diff_fiscalyear',
|
||||
context=context)
|
||||
|
||||
period = period_obj.browse(cursor, user, data['form']['period'],
|
||||
context=context)
|
||||
if period.fiscalyear.id != data['form']['fiscalyear']:
|
||||
raise ExceptWizard('UserError', 'The period must be ' \
|
||||
'in the selected fiscal year!')
|
||||
self.raise_user_error(cursor, 'period_in_fiscalyear',
|
||||
context=context)
|
||||
|
||||
journal = journal_obj.browse(cursor, user, data['form']['journal'],
|
||||
context=context)
|
||||
if not journal.centralised:
|
||||
raise ExceptWizard('UserError', 'The journal must be centralised!')
|
||||
self.raise_user_error(cursor, 'centralised_journal',
|
||||
context=context)
|
||||
|
||||
if not journal.credit_account or not journal.debit_account:
|
||||
raise ExceptWizard('UserError', 'The journal must have ' \
|
||||
'default debit/credit accounts!')
|
||||
self.raise_user_error(cursor,
|
||||
'journal_default_debit_credit_account',
|
||||
context=context)
|
||||
|
||||
ctx = context.copy()
|
||||
ctx['fiscalyear'] = data['form']['close_fiscalyear']
|
||||
|
||||
+15
-7
@@ -1,7 +1,7 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms.
|
||||
"Journal"
|
||||
|
||||
from trytond.osv import fields, OSV, ExceptORM
|
||||
from trytond.osv import fields, OSV
|
||||
from trytond.wizard import Wizard, WizardOSV
|
||||
|
||||
STATES = {
|
||||
@@ -148,6 +148,14 @@ class Period(OSV):
|
||||
'You can only open one journal per period!'),
|
||||
]
|
||||
self._order.insert(0, ('name', 'ASC'))
|
||||
self._error_messages.update({
|
||||
'modify_del_journal_period': 'You can not modify/delete ' \
|
||||
'a journal - period with moves!',
|
||||
'create_journal_period': 'You can not create ' \
|
||||
'a journal - period on a closed period!',
|
||||
'open_journal_period': 'You can not open ' \
|
||||
'a journal - period from a closed period!',
|
||||
})
|
||||
|
||||
def default_active(self, cursor, user, context=None):
|
||||
return True
|
||||
@@ -169,8 +177,8 @@ class Period(OSV):
|
||||
('period', '=', period.period.id),
|
||||
], limit=1, context=context)
|
||||
if move_ids:
|
||||
raise ExceptORM('Error', 'You can not modify/delete ' \
|
||||
'a journal - period with moves!')
|
||||
self.raise_user_error(cursor, 'modify_del_journal_period',
|
||||
context=context)
|
||||
return
|
||||
|
||||
def create(self, cursor, user, vals, context=None):
|
||||
@@ -179,8 +187,8 @@ class Period(OSV):
|
||||
period = period_obj.browse(cursor, user, vals['period'],
|
||||
context=context)
|
||||
if period.state == 'close':
|
||||
raise ExceptORM('UserError', 'You can not create ' \
|
||||
'a journal - period on a closed period!')
|
||||
self.raise_user_error(cursor, 'create_journal_period',
|
||||
context=context)
|
||||
return super(Period, self).create(cursor, user, vals, context=context)
|
||||
|
||||
def write(self, cursor, user, ids, vals, context=None):
|
||||
@@ -191,8 +199,8 @@ class Period(OSV):
|
||||
for journal_period in self.browse(cursor, user, ids,
|
||||
context=context):
|
||||
if journal_period.period.state == 'close':
|
||||
raise ExceptORM('UserError', 'You can not open ' \
|
||||
'a journal - period from a closed period!')
|
||||
self.raise_user_error(cursor, 'open_journal_period',
|
||||
context=context)
|
||||
return super(Period, self).write(cursor, user, ids, vals,
|
||||
context=context)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms.
|
||||
'Move'
|
||||
|
||||
from trytond.osv import fields, OSV, ExceptORM
|
||||
from trytond.osv import fields, OSV
|
||||
from trytond.wizard import Wizard, WizardOSV
|
||||
from trytond.report import Report
|
||||
from decimal import Decimal
|
||||
@@ -56,6 +56,13 @@ class Move(OSV):
|
||||
]
|
||||
self._order.insert(0, ('date', 'DESC'))
|
||||
self._order.insert(1, ('reference', 'DESC'))
|
||||
self._error_messages.update({
|
||||
'del_posted_move': 'You can not delete posted move!',
|
||||
'post_empty_move': 'You can not post an empty move!',
|
||||
'post_unbalanced_move': 'You can not post a unbalanced move!',
|
||||
'modify_posted_move': 'You can not modify a posted move ' \
|
||||
'in this journal!',
|
||||
})
|
||||
|
||||
def _auto_init(self, cursor, module_name):
|
||||
super(Move, self)._auto_init(cursor, module_name)
|
||||
@@ -163,8 +170,8 @@ class Move(OSV):
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
for move in self.browse(cursor, user, ids, context=context):
|
||||
if move.state == 'posted':
|
||||
raise ExceptORM('UserError',
|
||||
'You can not delete posted move!')
|
||||
self.raise_user_error(cursor, 'del_posted_move',
|
||||
context=context)
|
||||
if move.lines:
|
||||
move_line_ids = [x.id for x in move.lines]
|
||||
move_line_obj.unlink(cursor, user, move_line_ids,
|
||||
@@ -235,16 +242,16 @@ class Move(OSV):
|
||||
for move in moves:
|
||||
amount = Decimal('0.0')
|
||||
if not move.lines:
|
||||
raise ExceptORM('UserError',
|
||||
'You can not post an empty move!')
|
||||
self.raise_user_error(cursor, 'post_empty_move',
|
||||
context=context)
|
||||
company = None
|
||||
for line in move.lines:
|
||||
amount += line.debit - line.credit
|
||||
if not company:
|
||||
company = line.account.company
|
||||
if not currency_obj.is_zero(cursor, user, company.currency, amount):
|
||||
raise ExceptORM('UserError',
|
||||
'You can not post a unbalanced move!')
|
||||
self.raise_user_error(cursor, 'post_unbalanced_move',
|
||||
context=context)
|
||||
for move in moves:
|
||||
reference = sequence_obj.get_id(cursor, user,
|
||||
move.period.post_move_sequence.id)
|
||||
@@ -258,8 +265,8 @@ class Move(OSV):
|
||||
def draft(self, cursor, user, ids, context=None):
|
||||
for move in self.browse(cursor, user, ids, context=context):
|
||||
if not move.journal.update_posted:
|
||||
raise ExceptORM('UserError',
|
||||
'You can not modify a posted move in this journal!')
|
||||
self.raise_user_error(cursor, 'modify_posted_move',
|
||||
context=context)
|
||||
return self.write(cursor, user, ids, {
|
||||
'state': 'draft',
|
||||
}, context=context)
|
||||
@@ -289,6 +296,9 @@ class Reconciliation(OSV):
|
||||
'nor in the same account, nor in account to reconcile!',
|
||||
['lines']),
|
||||
]
|
||||
self._error_messages.update({
|
||||
'modify': 'You can not modify a reconciliation!',
|
||||
})
|
||||
|
||||
def default_name(self, cursor, user, context=None):
|
||||
sequence_obj = self.pool.get('ir.sequence')
|
||||
@@ -304,7 +314,7 @@ class Reconciliation(OSV):
|
||||
return res
|
||||
|
||||
def write(self, cursor, user, ids, vals, context=None):
|
||||
raise ExceptORM('UserError', 'You can not modify a reconciliation!')
|
||||
self.raise_user_error(cursor, 'modify', context=context)
|
||||
|
||||
def check_lines(self, cursor, user, ids):
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
@@ -402,6 +412,13 @@ class Line(OSV):
|
||||
'on_write',
|
||||
]
|
||||
self._order[0] = ('id', 'DESC')
|
||||
self._error_messages.update({
|
||||
'add_modify_closed_journal_period': 'You can not ' \
|
||||
'add/modify lines in a closed journal period!',
|
||||
'modify_posted_move': 'You can not modify line from a posted move!',
|
||||
'modify_reconciled': 'You can not modify reconciled line!',
|
||||
'no_journal': 'No journal defined!',
|
||||
})
|
||||
|
||||
def default_date(self, cursor, user, context=None):
|
||||
'''
|
||||
@@ -923,9 +940,8 @@ class Line(OSV):
|
||||
journal_period = journal_period_obj.browse(cursor, user,
|
||||
journal_period_ids[0], context=context)
|
||||
if journal_period.state == 'close':
|
||||
raise ExceptORM('UserError',
|
||||
'You can not add/modify lines \n' \
|
||||
'in a closed journal period!')
|
||||
self.raise_user_error(cursor,
|
||||
'add_modify_closed_journal_period', context=context)
|
||||
else:
|
||||
journal = journal_obj.browse(cursor, user, journal_id,
|
||||
context=context)
|
||||
@@ -945,11 +961,11 @@ class Line(OSV):
|
||||
journal_period_done = []
|
||||
for line in self.browse(cursor, user, ids, context=context):
|
||||
if line.move.state == 'posted':
|
||||
raise ExceptORM('UserError',
|
||||
'You can not modify line from a posted move!')
|
||||
self.raise_user_error(cursor, 'modify_posted_move',
|
||||
context=context)
|
||||
if line.reconciliation:
|
||||
raise ExceptORM('UserError',
|
||||
'You can not modify reconciled line!')
|
||||
self.raise_user_error(cursor, 'modify_reconciled',
|
||||
context=context)
|
||||
journal_period = (line.journal.id, line.period.id)
|
||||
if journal_period not in journal_period_done:
|
||||
self.check_journal_period_modify(cursor, user, line.period.id,
|
||||
@@ -992,7 +1008,8 @@ class Line(OSV):
|
||||
if not vals.get('move'):
|
||||
journal_id = vals.get('journal', context.get('journal'))
|
||||
if not journal_id:
|
||||
raise ExceptORM('Error', 'No journal defined!')
|
||||
self.raise_user_error(cursor, 'no_journal',
|
||||
context=context)
|
||||
journal = journal_obj.browse(cursor, user, journal_id,
|
||||
context=context)
|
||||
if journal.centralised:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms.
|
||||
'Period'
|
||||
|
||||
from trytond.osv import fields, OSV, ExceptORM
|
||||
from trytond.osv import fields, OSV
|
||||
from trytond.wizard import Wizard
|
||||
import datetime
|
||||
|
||||
@@ -39,6 +39,20 @@ class Period(OSV):
|
||||
'per fiscal year!', ['post_move_sequence']),
|
||||
]
|
||||
self._order.insert(0, ('start_date', 'ASC'))
|
||||
self._error_messages.update({
|
||||
'no_period_date': 'No period defined for this date!',
|
||||
'modify_del_period_moves': 'You can not modify/delete ' \
|
||||
'a period with moves!',
|
||||
'create_period_closed_fiscalyear': 'You can not create ' \
|
||||
'a period on a closed fiscal year!',
|
||||
'open_period_closed_fiscalyear': 'You can not open ' \
|
||||
'a period from a closed fiscal year!',
|
||||
'change_post_move_sequence': 'You can not change ' \
|
||||
'the post move sequence ' \
|
||||
'if there is already posted move in the period',
|
||||
'close_period_non_posted_move': 'You can not close ' \
|
||||
'a period with non posted moves!',
|
||||
})
|
||||
|
||||
def default_state(self, cursor, user, context=None):
|
||||
return 'open'
|
||||
@@ -86,7 +100,8 @@ class Period(OSV):
|
||||
], order=[('start_date', 'DESC')], limit=1, context=context)
|
||||
if not ids:
|
||||
if exception:
|
||||
raise ExceptORM('Error', 'No period defined for this date!')
|
||||
self.raise_user_error(cursor, 'no_period_date',
|
||||
context=context)
|
||||
else:
|
||||
return False
|
||||
return ids[0]
|
||||
@@ -97,8 +112,8 @@ class Period(OSV):
|
||||
('period', 'in', ids),
|
||||
], limit=1, context=context)
|
||||
if move_ids:
|
||||
raise ExceptORM('UserError', 'You can not modify/delete ' \
|
||||
'a period with moves!')
|
||||
self.raise_user_error(cursor, 'modify_del_period_moves',
|
||||
context=context)
|
||||
return
|
||||
|
||||
def search(self, cursor, user, args, offset=0, limit=None, order=None,
|
||||
@@ -126,8 +141,8 @@ class Period(OSV):
|
||||
fiscalyear = fiscalyear_obj.browse(cursor, user, vals['fiscalyear'],
|
||||
context=context)
|
||||
if fiscalyear.state == 'close':
|
||||
raise ExceptORM('UserError', 'You can not create ' \
|
||||
'a period on a closed fiscal year!')
|
||||
self.raise_user_error(cursor,
|
||||
'create_period_closed_fiscalyear', context=context)
|
||||
if not vals.get('post_move_sequence'):
|
||||
vals['post_move_sequence'] = fiscalyear.post_move_sequence.id
|
||||
return super(Period, self).create(cursor, user, vals, context=context)
|
||||
@@ -142,8 +157,8 @@ class Period(OSV):
|
||||
for period in self.browse(cursor, user, ids,
|
||||
context=context):
|
||||
if period.fiscalyear.state == 'close':
|
||||
raise ExceptORM('UserError', 'You can not open ' \
|
||||
'a period from a closed fiscal year!')
|
||||
self.raise_user_error(cursor,
|
||||
'open_period_closed_fiscalyear', context=context)
|
||||
if vals.get('post_move_sequence'):
|
||||
for period in self.browse(cursor, user, ids, context=context):
|
||||
if period.post_move_sequence and \
|
||||
@@ -153,9 +168,8 @@ class Period(OSV):
|
||||
('period', '=', period.id),
|
||||
('state', '=', 'posted'),
|
||||
], context=context):
|
||||
raise ExceptORM('UserError', 'You can not change ' \
|
||||
'the post move sequence \n' \
|
||||
'if there is already posted move in the period')
|
||||
self.raise_user_error(cursor,
|
||||
'change_post_move_sequence', context=context)
|
||||
return super(Period, self).write(cursor, user, ids, vals,
|
||||
context=context)
|
||||
|
||||
@@ -175,8 +189,8 @@ class Period(OSV):
|
||||
('period', 'in', ids),
|
||||
('state', '!=', 'posted'),
|
||||
], context=context):
|
||||
raise ExceptORM('UserError', 'You can not close ' \
|
||||
'a period with non posted moves!')
|
||||
self.raise_user_error(cursor, 'close_period_non_posted_move',
|
||||
context=context)
|
||||
#First close the period to be sure
|
||||
#it will not have new journal.period created between.
|
||||
self.write(cursor, user, ids, {
|
||||
|
||||
Reference in new issue
Block a user