Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(301)

Unified Diff: trytond/ir/sequence.py

Issue 1864045: Remove cursor, user and context instead use a Transaction (Closed)
Patch Set: Better Report.parse signature Created 14 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « trytond/ir/rule.py ('k') | trytond/ir/translation.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trytond/ir/sequence.py
===================================================================
--- a/trytond/ir/sequence.py
+++ b/trytond/ir/sequence.py
@@ -1,10 +1,12 @@
#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.model import ModelView, ModelSQL, fields
+from __future__ import with_statement
from string import Template
import datetime
+from trytond.model import ModelView, ModelSQL, fields
from trytond.tools import datetime_strftime
from trytond.pyson import In, Eval
+from trytond.transaction import Transaction
class SequenceType(ModelSQL, ModelView):
@@ -43,46 +45,42 @@
'invalid_prefix_suffix': 'Invalid prefix/suffix!',
})
- def default_active(self, cursor, user, context=None):
+ def default_active(self):
+ return True
+
+ def default_number_increment(self):
return 1
- def default_number_increment(self, cursor, user, context=None):
+ def default_number_next(self):
return 1
- def default_number_next(self, cursor, user, context=None):
- return 1
-
- def default_padding(self, cursor, user, context=None):
+ def default_padding(self):
return 0
- def default_code(self, cursor, user, context=None):
- if context is None:
- context = {}
- return context.get('code', False)
+ def default_code(self):
+ return Transaction().context.get('code', False)
- def code_get(self, cursor, user, context=None):
+ def code_get(self):
sequence_type_obj = self.pool.get('ir.sequence.type')
- sequence_type_ids = sequence_type_obj.search(cursor, user, [],
- context=context)
- sequence_types = sequence_type_obj.browse(cursor, user,
- sequence_type_ids, context=context)
+ sequence_type_ids = sequence_type_obj.search([])
+ sequence_types = sequence_type_obj.browse(sequence_type_ids)
return [(x.code, x.name) for x in sequence_types]
- def check_prefix_suffix(self, cursor, user, ids):
+ def check_prefix_suffix(self, ids):
"Check prefix and suffix"
- for sequence in self.browse(cursor, user, ids):
+ for sequence in self.browse(ids):
try:
- self._process(cursor, user, sequence.prefix)
- self._process(cursor, user, sequence.suffix)
+ self._process(sequence.prefix)
+ self._process(sequence.suffix)
except Exception:
return False
return True
- def _process(self, cursor, user, string, date=None, context=None):
+ def _process(self, string, date=None):
date_obj = self.pool.get('ir.date')
if not date:
- date = date_obj.today(cursor, user, context=context)
+ date = date_obj.today()
year = datetime_strftime(date, '%Y')
month = datetime_strftime(date, '%m')
day = datetime_strftime(date, '%d')
@@ -92,53 +90,43 @@
day=day,
)
- def get_id(self, cursor, user, domain, context=None):
+ def get_id(self, domain):
'''
Return sequence value for the domain
- :param cursor: the database cursor
- :param user: the user id
:param domain: a domain or a sequence id
- :param context: the context
:return: the sequence value
'''
- if context is None:
- context = {}
if isinstance(domain, (int, long)):
domain = [('id', '=', domain)]
# bypass rules on sequences
- if 'user' in context:
- context = context.copy()
- del context['user']
- sequence_ids = self.search(cursor, 0, domain, limit=1,
- context=context)
- date = context.get('date')
- if sequence_ids:
- sequence = self.browse(cursor, 0, sequence_ids[0],
- context=context)
- #Pre-fetch number_next
- number_next = sequence.number_next
+ with Transaction().set_context(user=False):
+ with Transaction().set_user(0):
+ sequence_ids = self.search(domain, limit=1)
+ date = Transaction().context.get('date')
+ if sequence_ids:
+ with Transaction().set_user(0):
+ sequence = self.browse(sequence_ids[0])
+ #Pre-fetch number_next
+ number_next = sequence.number_next
- self.write(cursor, 0, sequence.id, {
- 'number_next': number_next + sequence.number_increment,
- }, context=context)
+ self.write(sequence.id, {
+ 'number_next': (number_next +
+ sequence.number_increment),
+ })
- if number_next:
- return self._process(cursor, user, sequence.prefix, date=date,
- context=context) + \
- '%%0%sd' % sequence.padding % number_next + \
- self._process(cursor, user, sequence.suffix, date=date,
- context=context)
- else:
- return self._process(cursor, user, sequence.prefix, date=date,
- context=context) + \
- self._process(cursor, user, sequence.suffix, date=date,
- context=context)
- self.raise_user_error(cursor, 'missing', context=context)
+ if number_next:
+ return (self._process(sequence.prefix, date=date) +
+ '%%0%sd' % sequence.padding % number_next +
+ self._process(sequence.suffix, date=date))
+ else:
+ return (self._process(sequence.prefix, date=date) +
+ self._process(sequence.suffix, date=date))
+ self.raise_user_error('missing')
- def get(self, cursor, user, code, context=None):
- return self.get_id(cursor, user, [('code', '=', code)], context=context)
+ def get(self, code):
+ return self.get_id([('code', '=', code)])
Sequence()
@@ -148,9 +136,8 @@
_name = 'ir.sequence.strict'
_description = __doc__
- def get_id(self, cursor, user, clause, context=None):
- cursor.lock(self._table)
- return super(SequenceStrict, self).get_id(cursor, user, clause,
- context=context)
+ def get_id(self, clause):
+ Transaction().cursor.lock(self._table)
+ return super(SequenceStrict, self).get_id(clause)
SequenceStrict()
« no previous file with comments | « trytond/ir/rule.py ('k') | trytond/ir/translation.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b