From fe49a6623cb92a9820966da473b4729df7d8fee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 22 Apr 2008 17:47:52 +0200 Subject: [PATCH] Fix _order for new dict implementation --- account.py | 14 ++++++++++---- currency.py | 9 ++++++--- fiscalyear.py | 4 ++-- journal.py | 19 ++++++++++++++----- move.py | 12 +++++++----- period.py | 4 ++-- tax.py | 11 +++++++---- 7 files changed, 48 insertions(+), 25 deletions(-) diff --git a/account.py b/account.py index ba9159c4d9..ceba6db73c 100644 --- a/account.py +++ b/account.py @@ -15,7 +15,6 @@ from trytond.report.report import _LOCALE2WIN32 class Type(OSV): 'Account Type' _name = 'account.account.type' - _order = 'sequence, id' _description = __doc__ name = fields.Char('Name', size=None, required=True, translate=True) code = fields.Selection([ @@ -38,6 +37,10 @@ class Type(OSV): balance_sheet = fields.Boolean('Balance Sheet') income_statement = fields.Boolean('Income Statement') + def __init__(self): + super(Type, self).__init__() + self._order.insert(0, ('sequence', 'ASC')) + def default_account_type(self, cursor, user, context=None): return False @@ -95,7 +98,6 @@ class AccountTemplate(OSV): 'Account Template' _name = 'account.account.template' _description = __doc__ - _order = 'code, id' _parent_name = 'parents' name = fields.Char('Name', size=None, required=True, translate=True, @@ -115,6 +117,10 @@ class AccountTemplate(OSV): ('unreconciled', 'Unreconciled'), ], 'Deferral method', required=True) + def __init__(self): + super(AccountTemplate, self).__init__() + self._order.insert(0, ('code', 'ASC')) + def _get_account_value(self, cursor, user, template, context=None): res = {} res['name'] = template.name @@ -161,7 +167,6 @@ class Account(OSV): 'Account' _name = 'account.account' _description = __doc__ - _order = 'code, id' _parent_name = 'parents' name = fields.Char('Name', size=None, required=True, translate=True, @@ -207,6 +212,7 @@ class Account(OSV): ('check_recursion_parents', 'Error! You can not create recursive accounts.', ['parents']), ] + self._order.insert(0, ('code', 'ASC')) def default_active(self, cursor, user, context=None): return True @@ -580,7 +586,7 @@ class GeneralLegder(Report): account_ids = account_obj.search(cursor, user, [ ('company', '=', datas['form']['company']), - ], order='code, id', context=context) + ], order=[('code', 'ASC'), ('id', 'ASC')], context=context) start_period_ids = [0] if datas['form']['start_period']: diff --git a/currency.py b/currency.py index c64495563e..e9aa5f41c6 100644 --- a/currency.py +++ b/currency.py @@ -9,7 +9,6 @@ class Currency(OSV): 'Currency' _name = 'account.currency' _description = __doc__ - _order = 'code' name = fields.Char('Name', size=128, required=True, translate=True) code = fields.Char('Code', size=3, required=True) rate = fields.Function('get_rate', string='Current rate', digits=(12, 6)) @@ -18,6 +17,10 @@ class Currency(OSV): digits = fields.Integer('Diplay Digits') active = fields.Boolean('Active') + def __init__(self): + super(Currency, self).__init__() + self._order.insert(0, ('code', 'ASC')) + def default_active(self, cursor, user, context=None): return True @@ -56,7 +59,7 @@ class Currency(OSV): rate_ids = rate_obj.search(cursor, user, [ ('currency', '=', currency_id), ('date', '<=', date), - ], limit=1, order='date DESC') + ], limit=1, order=[('date', 'DESC')]) if rate_ids: res[currency_id] = rate_ids[0] else: @@ -119,7 +122,6 @@ class Rate(OSV): _name = 'account.currency.rate' _description = __doc__ _rec_name = 'date' - _order = 'date DESC, id' date = fields.Date('Date', required=True, select=1) rate = fields.Numeric('Rate', digits=(12, 6), required=1) currency = fields.Many2One('account.currency', 'Currency') @@ -130,6 +132,7 @@ class Rate(OSV): ('date_currency_uniq', 'UNIQUE(date, currency)', 'A currency can only have one rate by date!'), ] + self._order.insert(0, ('date', 'DESC')) def default_date(self, cursor, user, context=None): return time.strftime('%Y-%m-%d') diff --git a/fiscalyear.py b/fiscalyear.py index 53e57da810..ee2f929f7b 100644 --- a/fiscalyear.py +++ b/fiscalyear.py @@ -15,7 +15,6 @@ class FiscalYear(OSV): 'Fiscal Year' _name = 'account.fiscalyear' _description = __doc__ - _order = 'start_date' name = fields.Char('Name', size=None, required=True) code = fields.Char('Code', size=None) @@ -44,6 +43,7 @@ class FiscalYear(OSV): 'Error! You must have different post move sequence ' \ 'per fiscal year!', ['post_move_sequence']), ] + self._order.insert(0, ('start_date', 'ASC')) def default_state(self, cursor, user, context=None): return 'open' @@ -133,7 +133,7 @@ class FiscalYear(OSV): ids = self.search(cursor, user, [ ('start_date', '<=', date), ('end_date', '>=', date), - ], order='start_date DESC', limit=1, context=context) + ], order=[('start_date', 'DESC')], limit=1, context=context) if not ids: if exception: raise ExceptORM('Error', 'No fiscal year defined for this date!') diff --git a/journal.py b/journal.py index 3faf478ad7..1cf277b400 100644 --- a/journal.py +++ b/journal.py @@ -15,7 +15,6 @@ _ICONS = { class Type(OSV): 'Journal Type' _name = 'account.journal.type' - _order = 'code' _description = __doc__ name = fields.Char('Name', size=None, required=True, translate=True) code = fields.Char('Code', size=None, required=True) @@ -25,6 +24,7 @@ class Type(OSV): self._sql_constraints += [ ('code_uniq', 'UNIQUE(code)', 'Code must be unique!'), ] + self._order.insert(0, ('code', 'ASC')) Type() @@ -33,10 +33,13 @@ class View(OSV): 'Journal View' _name = 'account.journal.view' _description = __doc__ - _order = 'name, id' name = fields.Char('Name', size=None, required=True) columns = fields.One2Many('account.journal.view.column', 'view', 'Columns') + def __init__(self): + super(View, self).__init__() + self._order.insert(0, ('name', 'ASC')) + View() @@ -44,7 +47,6 @@ class Column(OSV): 'Journal View Column' _name = 'account.journal.view.column' _description = __doc__ - _order = 'sequence, id' name = fields.Char('Name', size=None, required=True) field = fields.Many2One('ir.model.field', 'Field', required=True, domain="[('model.model', '=', 'account.move.line')]") @@ -53,6 +55,10 @@ class Column(OSV): required = fields.Boolean('Required') readonly = fields.Boolean('Readonly') + def __init__(self): + super(Column, self).__init__() + self._order.insert(0, ('sequence', 'ASC')) + Column() @@ -60,7 +66,6 @@ class Journal(OSV): 'Journal' _name = 'account.journal' _description = __doc__ - _order = 'name, id' name = fields.Char('Name', size=None, required=True, translate=True) code = fields.Char('Code', size=None) @@ -84,6 +89,10 @@ class Journal(OSV): 'required': "centralised or type == 'cash'", }) + def __init__(self): + super(Journal, self).__init__() + self._order.insert(0, ('name', 'ASC')) + def default_active(self, cursor, user, context=None): return True @@ -118,7 +127,6 @@ class Period(OSV): 'Journal - Period' _name = 'account.journal.period' _description = __doc__ - _order = 'name, id' name = fields.Char('Name', size=None, required=True) journal = fields.Many2One('account.journal', 'Journal', required=True, @@ -138,6 +146,7 @@ class Period(OSV): ('journal_period_uniq', 'UNIQUE(journal, period)', 'You can only open one journal per period!'), ] + self._order.insert(0, ('name', 'ASC')) def default_active(self, cursor, user, context=None): return True diff --git a/move.py b/move.py index c41586405e..c78d627102 100644 --- a/move.py +++ b/move.py @@ -19,7 +19,6 @@ class Move(OSV): 'Account Move' _name = 'account.move' _description = __doc__ - _order = 'date DESC, reference DESC, id DESC' name = fields.Char('Name', size=None, required=True) reference = fields.Char('Reference', size=None, readonly=True, @@ -54,6 +53,8 @@ class Move(OSV): 'button_post', 'button_draft', ] + self._order.insert(0, ('date', 'DESC')) + self._order.insert(1, ('reference', 'DESC')) def _auto_init(self, cursor, module_name): super(Move, self)._auto_init(cursor, module_name) @@ -326,7 +327,6 @@ class Line(OSV): 'Account Move Line' _name = 'account.move.line' _description = __doc__ - _order = 'id DESC' name = fields.Char('Name', size=None, required=True) debit = fields.Numeric('Debit', digits=(16, 2), @@ -392,6 +392,7 @@ class Line(OSV): self._rpc_allowed += [ 'on_write', ] + self._order[0] = ('id', 'DESC') def default_date(self, cursor, user, context=None): ''' @@ -407,7 +408,7 @@ class Line(OSV): line_ids = self.search(cursor, user, [ ('journal', '=', context['journal']), ('period', '=', context['period']), - ], order='id DESC', limit=1, context=context) + ], order=[('id', 'DESC')], limit=1, context=context) if line_ids: line = self.browse(cursor, user, line_ids[0], context=context) res = line.date @@ -446,7 +447,7 @@ class Line(OSV): ('move.period', '=', context['period']), ('create_uid', '=', user), ('state', '=', 'draft'), - ], order='id DESC', limit=1, context=context) + ], order=[('id', 'DESC')], limit=1, context=context) if not line_ids: return values line = self.browse(cursor, user, line_ids[0], context=context) @@ -1677,7 +1678,8 @@ class GeneralJournal(Report): if datas['form']['posted']: clause.append(('state', '=', 'posted')) move_ids = move_obj.search(cursor, user, clause, - order='date, reference, id', context=context) + order=[('date', 'ASC'), ('reference', 'ASC'), ('id', 'ASC')], + context=context) return move_obj.browse(cursor, user, move_ids, context=context) def parse(self, cursor, user, report, objects, datas, context): diff --git a/period.py b/period.py index e548c1769a..d60ca9f129 100644 --- a/period.py +++ b/period.py @@ -13,7 +13,6 @@ class Period(OSV): 'Period' _name = 'account.period' _description = __doc__ - _order = 'start_date' name = fields.Char('Name', size=None, required=True) code = fields.Char('Code', size=None) @@ -38,6 +37,7 @@ class Period(OSV): 'Error! You must have different post move sequence ' \ 'per fiscal year!', ['post_move_sequence']), ] + self._order.insert(0, ('start_date', 'ASC')) def default_state(self, cursor, user, context=None): return 'open' @@ -78,7 +78,7 @@ class Period(OSV): ids = self.search(cursor, user, [ ('start_date', '<=', date), ('end_date', '>=', date), - ], order='start_date DESC', limit=1, context=context) + ], order=[('start_date', 'DESC')], limit=1, context=context) if not ids: if exception: raise ExceptORM('Error', 'No period defined for this date!') diff --git a/tax.py b/tax.py index 4fd817efa3..c94770ab0d 100644 --- a/tax.py +++ b/tax.py @@ -26,7 +26,6 @@ class Code(OSV): 'Tax Code' _name = 'account.tax.code' _description = __doc__ - _order = 'code, id' name = fields.Char('Name', size=None, required=True, select=1) code = fields.Char('Code', size=None, select=1) @@ -44,6 +43,7 @@ class Code(OSV): ('check_recursion', 'Error! You can not create recursive tax code!', ['parent']), ] + self._order.insert(0, ('code', 'ASC')) def default_active(self, cursor, user, context=None): return True @@ -195,7 +195,6 @@ class Tax(OSV): ''' _name = 'account.tax' _description = 'Account Tax' - _order = 'sequence, id' name = fields.Char('Name', size=None, required=True, translate=True) group = fields.Many2One('account.tax.group', 'Group', required=True, @@ -280,6 +279,10 @@ class Tax(OSV): 'readonly': "type == 'none'", }) + def __init__(self): + super(Tax, self).__init__() + self._order.insert(0, ('sequence', 'ASC')) + def default_active(self, cursor, user, context=None): return True @@ -351,7 +354,7 @@ class Tax(OSV): ''' ids = self.search(cursor, user, [ ('id', 'in', ids), - ], order='sequence, id', context=context) + ], order=[('sequence', 'ASC'), ('id', 'ASC')], context=context) taxes = self.browse(cursor, user, ids, context=context) res = self._unit_compute(cursor, user, taxes, price_unit, context=context) @@ -407,7 +410,7 @@ class Tax(OSV): ''' ids = self.search(cursor, user, [ ('id', 'in', ids), - ], order='sequence, id', context=context) + ], order=[('sequence', 'ASC'), ('id', 'ASC')], context=context) taxes = self.browse(cursor, user, ids, context=context) taxes.reverse() res = self._unit_compute_inv(cursor, user, taxes, price_unit,