本文整理汇总了Python中trytond.transaction.Transaction.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.copy方法的具体用法?Python Transaction.copy怎么用?Python Transaction.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trytond.transaction.Transaction
的用法示例。
在下文中一共展示了Transaction.copy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search_quantity
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import copy [as 别名]
def search_quantity(self, name, domain=None):
date_obj = self.pool.get('ir.date')
context = Transaction().context
if not (context and context.get('locations') and domain):
return []
if name == 'quantity' and \
context.get('stock_date_end') and \
context.get('stock_date_end') > \
date_obj.today():
context = context.copy()
context['stock_date_end'] = date_obj.today()
if name == 'forecast_quantity':
context = context.copy()
context['forecast'] = True
if not context.get('stock_date_end'):
context['stock_date_end'] = datetime.date.max
pbl = self.products_by_location(
location_ids=context['locations'], with_childs=True,
skip_zero=False).iteritems()
processed_lines = []
for (location, product), quantity in pbl:
processed_lines.append({'location': location, #XXX useful ?
'product': product,
name: quantity})
res= [line['product'] for line in processed_lines \
if self._search_quantity_eval_domain(line, domain)]
return [('id', 'in', res)]
示例2: BrowseRecord
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import copy [as 别名]
#.........这里部分代码省略.........
ids = model2ids.setdefault(model, [])
ids.append(data[i])
local_cache = model2cache.setdefault(model,
LRUDict(RECORD_CACHE_SIZE))
data[i] = BrowseRecord(data[i], model,
ids, local_cache)
elif (model and j._type in ('one2many', 'many2many')):
_datetime = None
if hasattr(j, 'datetime_field') and j.datetime_field:
_datetime = data[j.datetime_field]
with Transaction().set_context(
_datetime=_datetime):
ids = model2ids.setdefault(model, [])
ids.extend(data[i])
local_cache = model2cache.setdefault(model,
LRUDict(RECORD_CACHE_SIZE))
data[i] = BrowseRecordList(
BrowseRecord(x, model, ids, local_cache)
for x in data[i])
if (isinstance(j, fields.Function)
or isinstance(data[i], (BrowseRecord,
BrowseRecordList))):
if data['id'] == self.id and i == name:
result = data[i]
self._local_data.setdefault(data['id'], {})[i] = \
data[i]
del data[i]
self._data.setdefault(data['id'], {}).update(data)
if data['id'] == self.id and name in data:
result = data[name]
return result
def __getattr__(self, name):
# TODO raise an AttributeError exception
return self[name]
def __contains__(self, name):
return (name in self._model._columns) \
or (name in self._model._inherit_fields) \
or hasattr(self._model, name)
def __hasattr__(self, name):
return name in self
def __int__(self):
return self.id
def __str__(self):
return "BrowseRecord(%s, %d)" % (self._model_name, self.id)
def __eq__(self, other):
return (self._model_name, self.id) == (other._model_name, other.id)
def __ne__(self, other):
return (self._model_name, self.id) != (other._model_name, other.id)
# we need to define __unicode__ even though we've already defined __str__
# because we have overridden __getattr__
def __unicode__(self):
return unicode(str(self))
def __hash__(self):
return hash((self._model_name, self.id))
def __nonzero__(self):
return True
__repr__ = __str__
def setLang(self, lang):
self._context = self._context.copy()
prev_lang = self._context.get('language') or CONFIG['language']
self._context['language'] = lang
for cache in (self._cache, {self._model_name: self._local_data}):
language_cache = cache.setdefault('_language_cache', {})
for model in cache:
if model == '_language_cache':
continue
for record_id in cache[model]:
language_cache.setdefault(prev_lang,
LRUDict(MODEL_CACHE_SIZE)).setdefault(model,
LRUDict(RECORD_CACHE_SIZE))[record_id] = \
cache[model][record_id]
if lang in language_cache \
and model in language_cache[lang] \
and record_id in language_cache[lang][model]:
cache[model][record_id] = \
language_cache[lang][model][record_id]
else:
cache[model][record_id] = {}
def get_eval(self, name):
res = self[name]
if isinstance(res, BrowseRecord):
res = res.id
if isinstance(res, BrowseRecordList):
res = res.get_eval()
if isinstance(res, BrowseRecordNull):
res = False
return res