本文整理汇总了Python中trytond.transaction.Transaction.execute方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.execute方法的具体用法?Python Transaction.execute怎么用?Python Transaction.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trytond.transaction.Transaction
的用法示例。
在下文中一共展示了Transaction.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __register__
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().connection.cursor()
pool = Pool()
Line = pool.get('account.invoice.payment_term.line')
sql_table = cls.__table__()
line = Line.__table__()
# Migration from 4.0: rename long table
old_model_name = 'account.invoice.payment_term.line.relativedelta'
old_table = config.get(
'table', old_model_name, default=old_model_name.replace('.', '_'))
if TableHandler.table_exist(old_table):
TableHandler.table_rename(old_table, cls._table)
super(PaymentTermLineRelativeDelta, cls).__register__(module_name)
line_table = Line.__table_handler__(module_name)
# Migration from 3.4
fields = ['day', 'month', 'weekday', 'months', 'weeks', 'days']
if any(line_table.column_exist(f) for f in fields):
columns = ([line.id.as_('line')]
+ [Column(line, f) for f in fields])
cursor.execute(*sql_table.insert(
columns=[sql_table.line]
+ [Column(sql_table, f) for f in fields],
values=line.select(*columns)))
for field in fields:
line_table.drop_column(field)
示例2: init
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def init(self, module_name):
cursor = Transaction().cursor
# Migration from 1.6: corrected misspelling of ounce (was once)
cursor.execute("UPDATE ir_model_data "\
"SET fs_id = REPLACE(fs_id, 'uom_once', 'uom_ounce') "\
"WHERE fs_id = 'uom_once' AND module = 'product'")
super(Uom, self).init(module_name)
示例3: __register__
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
sql_table = cls.__table__()
super(PaymentTermLine, cls).__register__(module_name)
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
# Migration from 1.0 percent change into percentage
if table.column_exist('percent'):
cursor.execute(*sql_table.update(
columns=[sql_table.percentage],
values=[sql_table.percent * 100]))
table.drop_column('percent', exception=True)
# Migration from 2.2
if table.column_exist('delay'):
cursor.execute(*sql_table.update(
columns=[sql_table.day],
values=[31],
where=sql_table.delay == 'end_month'))
table.drop_column('delay', exception=True)
lines = cls.search([])
for line in lines:
if line.percentage:
cls.write([line], {
'divisor': cls.round(Decimal('100.0') /
line.percentage, cls.divisor.digits[1]),
})
# Migration from 2.4: drop required on sequence
table.not_null_action('sequence', action='remove')
示例4: create
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def create(self, vals):
later = {}
vals = vals.copy()
cr = Transaction().cursor
for field in vals:
if field in self._columns\
and hasattr(self._columns[field], 'set'):
later[field] = vals[field]
for field in later:
del vals[field]
if vals.get('invoice_ref') == ',':
del vals['invoice_ref']
if vals.get('document_ref') == ',':
del vals['invoice_ref']
if cr.nextid(self._table):
cr.setnextid(self._table, cr.currid(self._table))
new_id = super(DocumentRequest, self).create(vals)
request = self.browse(new_id)
new_id = request.document.id
cr.execute('UPDATE "' + self._table + '" SET id = %s '\
'WHERE id = %s', (request.document.id, request.id))
ModelStorage.delete(self, request.id)
self.write(new_id, later)
res = self.browse(new_id)
return res.id
示例5: restore_default_party_lang_from_4_2
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def restore_default_party_lang_from_4_2(cls):
from trytond.transaction import Transaction
from sql import Null, Table, Cast
from sql.operators import Concat
from trytond.pool import Pool
TableHandler = backend.get('TableHandler')
if not TableHandler.table_exist('ir_property'):
return
pool = Pool()
property = Table('ir_property')
Lang = pool.get('ir.lang')
field = pool.get('ir.model.field').__table__()
lang = Lang.__table__()
cursor = Transaction().connection.cursor()
query_table = property.join(lang, condition=(
property.value == Concat('ir.lang,', Cast(lang.id, 'VARCHAR'))
)).join(field, condition=((property.field == field.id) &
(field.name == 'lang')))
cursor.execute(
*query_table.select(lang.id, where=property.res == Null))
result = cursor.fetchone()
if result:
result = list(result)
default_lang = Lang(result[0])
print('Default Language restored [%s]' % default_lang.rec_name)
pool.get('party.configuration.party_lang'
).create([{'party_lang': default_lang}])
else:
print('No default language on party configuration found')
示例6: __register__
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def __register__(cls, module_name):
TimesheetWork = Pool().get('timesheet.work')
cursor = Transaction().cursor
table_project_work = TableHandler(cursor, cls, module_name)
table_timesheet_work = TableHandler(cursor, TimesheetWork, module_name)
migrate_sequence = (not table_project_work.column_exist('sequence')
and table_timesheet_work.column_exist('sequence'))
super(Work, cls).__register__(module_name)
# Migration from 2.0: copy sequence from timesheet to project
if migrate_sequence:
cursor.execute(
'SELECT t.sequence, t.id '
'FROM "%s" AS t '
'JOIN "%s" AS p ON (p.work = t.id)' % (
TimesheetWork._table, cls._table))
for sequence, id_ in cursor.fetchall():
sql = ('UPDATE "%s" '
'SET sequence = %%s '
'WHERE work = %%s' % cls._table)
cursor.execute(sql, (sequence, id_))
# Migration from 2.4: drop required on sequence
table_project_work.not_null_action('sequence', action='remove')
示例7: get_translation_4_nereid
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def get_translation_4_nereid(cls, module, ttype, lang, source):
"Return translation for source"
ttype = unicode(ttype)
lang = unicode(lang)
source = unicode(source)
cache_key = (lang, ttype, source, module)
trans = cls._nereid_translation_cache.get(cache_key, -1)
if trans != -1:
return trans
cursor = Transaction().cursor
table = cls.__table__()
where = (
(table.lang == lang) &
(table.type == ttype) &
(table.value != '') &
(table.value != None) &
(table.fuzzy == False) &
(table.src == source)
)
if module is not None:
where &= (table.module == module)
cursor.execute(*table.select(table.value, where=where))
res = cursor.fetchone()
if res:
cls._nereid_translation_cache.set(cache_key, res[0])
return res[0]
else:
cls._nereid_translation_cache.set(cache_key, False)
return None
示例8: copy_selection_options
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def copy_selection_options():
"""
Copy the selection field options and create options
for the selection field.
"""
Option = Pool().get('product.attribute.selection_option')
cursor = Transaction().cursor
cursor.execute(
"""
SELECT id, selection
FROM product_attribute
WHERE type_='selection'
"""
)
# Key value map
attribute_kv_map = defaultdict(dict)
for row in cursor.fetchall():
id, selection = row
for k, v in get_selection_json(selection):
option = Option(
name=v, attribute=id
)
option.save()
attribute_kv_map[id][k] = option.id
print "Created selection values for %d attributes" % len(attribute_kv_map)
return attribute_kv_map
示例9: column_rename
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def column_rename(self, old_name, new_name, exception=False):
cursor = Transaction().connection.cursor()
if self.column_exist(old_name) and not self.column_exist(new_name):
temp_table = "_temp_%s" % self.table_name
TableHandler.table_rename(self.table_name, temp_table)
new_table = TableHandler(self._model, history=self.history)
for column, (notnull, hasdef, size, typname) in self._columns.iteritems():
if column == old_name:
column = new_name
new_table.add_raw_column(column, typname, False, field_size=size)
new_columns = new_table._columns.keys()
old_columns = [x if x != old_name else new_name for x in new_columns]
cursor.execute(
(
'INSERT INTO "%s" ('
+ ",".join('"%s"' % x for x in new_columns)
+ ") SELECT "
+ ",".join('"%s"' % x for x in old_columns)
+ " "
+ 'FROM "%s"'
)
% (self.table_name, temp_table)
)
cursor.execute('DROP TABLE "%s"' % temp_table)
self._update_definitions()
elif exception and self.column_exist(new_name):
raise Exception(
"Unable to rename column %s.%s to %s.%s: "
"%s.%s already exist!"
% (self.table_name, old_name, self.table_name, new_name, self.table_name, new_name)
)
示例10: __register__
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
sql_table = cls.__table__()
table = TableHandler(cursor, cls, module_name)
if not table.column_exist('shop'):
table.add_raw_column(
'shop',
cls.shop.sql_type(),
cls.shop.sql_format, None, None
)
else:
Shop = Pool().get('sale.shop')
shops = Shop.search([])
if shops:
sales = cls.search([
('shop', '=', None),
])
for sale in sales:
cursor.execute(*sql_table.update(
columns=[sql_table.shop],
values=[shops[0].id],
where=sql_table.id == sale.id))
else:
logging.getLogger('sale shop').warning(
'You must to create a shop and update module '
'to assign current sales to new shop.')
super(Sale, cls).__register__(module_name)
示例11: get_lastmodified
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def get_lastmodified(cls, uri, cache=None):
pool = Pool()
object_name, object_id = cls._uri2object(uri, cache=cache)
if object_name == 'ir.attachment':
Model = pool.get(object_name)
if object_id:
if cache is not None:
cache.setdefault(Model.__name__, {})
ids = cache[Model.__name__].keys()
if object_id not in ids:
ids.append(object_id)
elif 'lastmodified' in cache[Model.__name__][object_id]:
return cache[Model.__name__][object_id][
'lastmodified']
else:
ids = [object_id]
res = None
cursor = Transaction().cursor
table = Model.__table__()
for sub_ids in grouped_slice(ids):
red_sql = reduce_ids(table.id, sub_ids)
cursor.execute(*table.select(table.id,
Extract('EPOCH',
Coalesce(table.write_date, table.create_date)),
where=red_sql))
for object_id2, date in cursor.fetchall():
if object_id2 == object_id:
res = date
if cache is not None:
cache[Model.__name__].setdefault(object_id2, {})
cache[Model.__name__][object_id2][
'lastmodified'] = date
if res is not None:
return res
return time.time()
示例12: get_creationdate
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def get_creationdate(cls, uri, cache=None):
pool = Pool()
object_name, object_id = cls._uri2object(uri, cache=cache)
if object_name == 'ir.attachment':
Model = pool.get(object_name)
if object_id:
if cache is not None:
cache.setdefault(Model.__name__, {})
ids = cache[Model.__name__].keys()
if object_id not in ids:
ids.append(object_id)
elif 'creationdate' in cache[Model.__name__][object_id]:
return cache[Model.__name__][object_id][
'creationdate']
else:
ids = [object_id]
res = None
cursor = Transaction().cursor
for i in range(0, len(ids), cursor.IN_MAX):
sub_ids = ids[i:i + cursor.IN_MAX]
red_sql, red_ids = reduce_ids('id', sub_ids)
cursor.execute('SELECT id, '
'EXTRACT(epoch FROM create_date) '
'FROM "' + Model._table + '" '
'WHERE ' + red_sql, red_ids)
for object_id2, date in cursor.fetchall():
if object_id2 == object_id:
res = date
if cache is not None:
cache[Model.__name__].setdefault(object_id2, {})
cache[Model.__name__][object_id2][
'creationdate'] = date
if res is not None:
return res
return time.time()
示例13: __register__
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def __register__(cls, module_name):
pool = Pool()
Party = pool.get('party.party')
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
party = Party.__table__()
super(PartyIdentifier, cls).__register__(module_name)
party_h = TableHandler(cursor, Party, module_name)
if (party_h.column_exist('vat_number')
and party_h.column_exist('vat_country')):
identifiers = []
cursor.execute(*party.select(
party.id, party.vat_number, party.vat_country,
where=(party.vat_number != Null)
| (party.vat_country != Null)))
for party_id, number, country in cursor.fetchall():
code = (country or '') + (number or '')
if not code:
continue
type = None
if vat.is_valid(code):
type = 'eu_vat'
identifiers.append(
cls(party=party_id, code=code, type=type))
cls.save(identifiers)
party_h.drop_column('vat_number')
party_h.drop_column('vat_country')
示例14: transition_check
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def transition_check(self):
Plots = Pool().get('forest.plot')
Preco = Pool().get('forest_work.preconisation')
plots_succeed = []
plots_failed = []
Lignes = Preco.browse(Transaction().context.get('active_ids'))
for ligne in Lignes:
cursor = Transaction().cursor
cursor.execute(
'SELECT p.id '
'FROM forest_plot p '
'WHERE p.id=%s '
'GROUP BY p.id' % (ligne.plot.id))
for plotid in cursor.fetchall():
plots = Plots.browse(plotid)
for plot in plots:
try:
if plot.travaux:
print "plots_failed ok"
self.create_travaux(plot)
plots_failed.append(plot.id)
else:
print "plots_succeed ok"
self.create_travaux(plot)
plots_succeed.append(plot.id)
except Exception, e:
raise
self.result.plots_succeed = plots_succeed
self.result.plots_failed = plots_failed
示例15: __register__
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import execute [as 别名]
def __register__(cls, module_name):
pool = Pool()
Sequence = pool.get('account.fiscalyear.invoice_sequence')
sequence = Sequence.__table__()
sql_table = cls.__table__()
super(FiscalYear, cls).__register__(module_name)
cursor = Transaction().connection.cursor()
table = cls.__table_handler__(module_name)
# Migration from 4.2: Use Match pattern for sequences
if (table.column_exist('in_invoice_sequence')
and table.column_exist('in_credit_note_sequence')
and table.column_exist('out_invoice_sequence')
and table.column_exist('out_credit_note_sequence')):
cursor.execute(*sequence.insert(columns=[
sequence.sequence, sequence.fiscalyear,
sequence.company,
sequence.out_invoice_sequence,
sequence.out_credit_note_sequence,
sequence.in_invoice_sequence,
sequence.in_credit_note_sequence],
values=sql_table.select(
Literal(20), sql_table.id,
sql_table.company,
sql_table.out_invoice_sequence,
sql_table.out_credit_note_sequence,
sql_table.in_invoice_sequence,
sql_table.in_credit_note_sequence)))
table.drop_column('out_invoice_sequence')
table.drop_column('out_credit_note_sequence')
table.drop_column('in_invoice_sequence')
table.drop_column('in_credit_note_sequence')