本文整理汇总了Python中trytond.transaction.Transaction.fetchall方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.fetchall方法的具体用法?Python Transaction.fetchall怎么用?Python Transaction.fetchall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trytond.transaction.Transaction
的用法示例。
在下文中一共展示了Transaction.fetchall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_active
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [as 别名]
def validate_active(self):
#Deactivate mandate as unit mandate on canceled state
if (self.id > 0) and self.state=='canceled':
condoparties = Pool().get('condo.party').__table__()
condopayments = Pool().get('condo.payment').__table__()
cursor = Transaction().connection.cursor()
cursor.execute(*condopayments.select(condopayments.id,
where=(condopayments.sepa_mandate == self.id) & (
(condopayments.state == 'draft') | (condopayments.state == 'approved')),
))
ids = [ids for (ids,) in cursor.fetchall()]
if len(ids):
self.raise_user_error('Can\'t cancel mandate "%s".\nThere are %s payments in draft or approved state with this mandate!',
(self.identification, len(ids)))
cursor.execute(*condoparties.select(condoparties.id,
where=(condoparties.sepa_mandate == self.id)))
ids = [ids for (ids,) in cursor.fetchall()]
if len(ids):
self.raise_user_warning('warn_canceled_mandate',
'Mandate "%s" will be canceled as mean of payment in %d unit(s)/apartment(s)!', (self.identification, len(ids)))
for sub_ids in grouped_slice(ids):
red_sql = reduce_ids(condoparties.id, sub_ids)
# Use SQL to prevent double validate loop
cursor.execute(*condoparties.update(
columns=[condoparties.sepa_mandate],
values=[None],
where=red_sql))
示例2: _update_definitions
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [as 别名]
def _update_definitions(self, columns=None, indexes=None):
if columns is None and indexes is None:
columns = indexes = True
cursor = Transaction().connection.cursor()
# Fetch columns definitions from the table
if columns:
cursor.execute('PRAGMA table_info("' + self.table_name + '")')
self._columns = {}
for _, column, type_, notnull, hasdef, _ in cursor.fetchall():
column = re.sub(r"^\"|\"$", "", column)
match = re.match(r"(\w+)(\((.*?)\))?", type_)
if match:
typname = match.group(1).upper()
size = match.group(3) and int(match.group(3)) or 0
else:
typname = type_.upper()
size = -1
self._columns[column] = {"notnull": notnull, "hasdef": hasdef, "size": size, "typname": typname}
# Fetch indexes defined for the table
if indexes:
try:
cursor.execute('PRAGMA index_list("' + self.table_name + '")')
except IndexError: # There is sometimes IndexError
cursor.execute('PRAGMA index_list("' + self.table_name + '")')
self._indexes = [l[1] for l in cursor.fetchall()]
示例3: button_process_continue
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [as 别名]
def button_process_continue(self, ids, start=False):
cr = Transaction().cursor
categs = self.read(ids,['category','exclusif','party', 'sales_purchase_active', 'profiling_active'])
for categ in categs:
if start:
if categ['exclusif']:
cr.execute('delete from party_category_rel where category=%s', (categ['categ'][0],))
id = categ['id']
cr.execute('select id from res_party order by id ')
partys = [x[0] for x in cr.fetchall()]
if categ['sales_purchase_active']:
to_remove_list=[]
cr.execute('select id from ekd_crm_segmentation_line where segmentation=%s', (id,))
line_ids = [x[0] for x in cr.fetchall()]
for pid in partys:
if (not self.pool.get('ekd.crm.segmentation.line').test(cr, uid, line_ids, pid)):
to_remove_list.append(pid)
for pid in to_remove_list:
partys.remove(pid)
for party in partys:
cr.execute('insert into party_category_rel (category,party) values (%s,%s)', (categ['categ'][0],party))
cr.commit()
self.write([id], {'state':'not running', 'party':0})
cr.commit()
return True
示例4: _purchase_cost
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [as 别名]
def _purchase_cost(cls, works):
'Compute direct purchase cost'
pool = Pool()
Currency = pool.get('currency.currency')
PurchaseLine = pool.get('purchase.line')
InvoiceLine = pool.get('account.invoice.line')
Invoice = pool.get('account.invoice')
Company = pool.get('company.company')
cursor = Transaction().cursor
table = cls.__table__()
purchase_line = PurchaseLine.__table__()
invoice_line = InvoiceLine.__table__()
invoice = Invoice.__table__()
company = Company.__table__()
amounts = defaultdict(Decimal)
work_ids = [w.id for w in works]
work2currency = {}
iline2work = {}
for sub_ids in grouped_slice(work_ids):
where = reduce_ids(table.id, sub_ids)
cursor.execute(*table.join(purchase_line,
condition=purchase_line.work == table.id
).join(invoice_line,
condition=invoice_line.origin == Concat(
'purchase.line,', purchase_line.id)
).join(invoice,
condition=invoice_line.invoice == invoice.id
).select(invoice_line.id, table.id,
where=where & ~invoice.state.in_(['draft', 'cancel'])))
iline2work.update(cursor.fetchall())
cursor.execute(*table.join(company,
condition=table.company == company.id
).select(table.id, company.currency,
where=where))
work2currency.update(cursor.fetchall())
currencies = Currency.browse(set(work2currency.itervalues()))
id2currency = {c.id: c for c in currencies}
invoice_lines = InvoiceLine.browse(iline2work.keys())
for invoice_line in invoice_lines:
invoice = invoice_line.invoice
work_id = iline2work[invoice_line.id]
currency_id = work2currency[work_id]
currency = id2currency[currency_id]
if currency != invoice.currency:
with Transaction().set_context(date=invoice.currency_date):
amount = Currency.compute(invoice.currency,
invoice_line.amount, currency)
else:
amount = invoice_line.amount
amounts[work_id] += amount
return amounts
示例5: _load_modules
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [as 别名]
def _load_modules():
global res
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
# Migration from 3.6: remove double module
old_table = 'ir_module_module'
new_table = 'ir_module'
if TableHandler.table_exist(cursor, old_table):
TableHandler.table_rename(cursor, old_table, new_table)
if update:
cursor.execute(*ir_module.select(ir_module.name,
where=ir_module.state.in_(('installed', 'to install',
'to upgrade', 'to remove'))))
else:
cursor.execute(*ir_module.select(ir_module.name,
where=ir_module.state.in_(('installed', 'to upgrade',
'to remove'))))
module_list = [name for (name,) in cursor.fetchall()]
if update:
module_list += update
graph = create_graph(module_list)[0]
try:
load_module_graph(graph, pool, update, lang)
except Exception:
cursor.rollback()
raise
if update:
cursor.execute(*ir_module.select(ir_module.name,
where=(ir_module.state == 'to remove')))
fetchall = cursor.fetchall()
if fetchall:
for (mod_name,) in fetchall:
# TODO check if ressource not updated by the user
cursor.execute(*ir_model_data.select(ir_model_data.model,
ir_model_data.db_id,
where=(ir_model_data.module == mod_name),
order_by=ir_model_data.id.desc))
for rmod, rid in cursor.fetchall():
Model = pool.get(rmod)
Model.delete([Model(rid)])
cursor.commit()
cursor.execute(*ir_module.update([ir_module.state],
['uninstalled'],
where=(ir_module.state == 'to remove')))
cursor.commit()
res = False
Module = pool.get('ir.module')
Module.update_list()
cursor.commit()
Cache.resets(database_name)
示例6: _get_invoiced_amount_timesheet
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [as 别名]
def _get_invoiced_amount_timesheet(cls, works):
pool = Pool()
TimesheetWork = pool.get('timesheet.work')
TimesheetLine = pool.get('timesheet.line')
InvoiceLine = pool.get('account.invoice.line')
Company = pool.get('company.company')
Currency = pool.get('currency.currency')
cursor = Transaction().cursor
table = cls.__table__()
timesheet_work = TimesheetWork.__table__()
timesheet_line = TimesheetLine.__table__()
invoice_line = InvoiceLine.__table__()
company = Company.__table__()
amounts = {}
work2currency = {}
work_ids = [w.id for w in works]
for sub_ids in grouped_slice(work_ids):
where = reduce_ids(table.id, sub_ids)
cursor.execute(*table.join(timesheet_work,
condition=table.work == timesheet_work.id
).join(timesheet_line,
condition=timesheet_line.work == timesheet_work.id
).join(invoice_line,
condition=timesheet_line.invoice_line == invoice_line.id
).select(table.id,
Sum(timesheet_line.duration * invoice_line.unit_price),
where=where,
group_by=table.id))
amounts.update(cursor.fetchall())
cursor.execute(*table.join(company,
condition=table.company == company.id
).select(table.id, company.currency,
where=where))
work2currency.update(cursor.fetchall())
currencies = Currency.browse(set(work2currency.itervalues()))
id2currency = {c.id: c for c in currencies}
for work in works:
currency = id2currency[work2currency[work.id]]
amount = amounts.get(work.id, 0)
if isinstance(amount, datetime.timedelta):
amount = amount.total_seconds()
amount = amount / 60 / 60
amounts[work.id] = currency.round(Decimal(str(amount)))
return amounts
示例7: __register__
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [as 别名]
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
sql_table = cls.__table__()
# Migration from 2.2 new field currency
created_currency = table.column_exist('currency')
super(ProductSupplier, cls).__register__(module_name)
# Migration from 2.2 fill currency
if not created_currency:
Company = Pool().get('company.company')
company = Company.__table__()
limit = cursor.IN_MAX
cursor.execute(*sql_table.select(Count(sql_table.id)))
product_supplier_count, = cursor.fetchone()
for offset in range(0, product_supplier_count, limit):
cursor.execute(*sql_table.join(company,
condition=sql_table.company == company.id
).select(sql_table.id, company.currency,
order_by=sql_table.id,
limit=limit, offset=offset))
for product_supplier_id, currency_id in cursor.fetchall():
cursor.execute(*sql_table.update(
columns=[sql_table.currency],
values=[currency_id],
where=sql_table.id == product_supplier_id))
# Migration from 2.4: drop required on sequence
table.not_null_action('sequence', action='remove')
# Migration from 2.6: drop required on delivery_time
table.not_null_action('delivery_time', action='remove')
# Migration from 3.8: change delivery_time inte timedelta lead_time
if table.column_exist('delivery_time'):
cursor.execute(*sql_table.select(
sql_table.id, sql_table.delivery_time))
for id_, delivery_time in cursor.fetchall():
if delivery_time is None:
continue
lead_time = datetime.timedelta(days=delivery_time)
cursor.execute(*sql_table.update(
[sql_table.lead_time],
[lead_time],
where=sql_table.id == id_))
table.drop_column('delivery_time')
示例8: _get_invoiced_amount_progress
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [as 别名]
def _get_invoiced_amount_progress(cls, works):
pool = Pool()
Progress = pool.get('project.work.invoiced_progress')
InvoiceLine = pool.get('account.invoice.line')
Company = pool.get('company.company')
Currency = pool.get('currency.currency')
cursor = Transaction().cursor
table = cls.__table__()
progress = Progress.__table__()
invoice_line = InvoiceLine.__table__()
company = Company.__table__()
amounts = defaultdict(Decimal)
work2currency = {}
work_ids = [w.id for w in works]
for sub_ids in grouped_slice(work_ids):
where = reduce_ids(table.id, sub_ids)
cursor.execute(*table.join(progress,
condition=progress.work == table.id
).join(invoice_line,
condition=progress.invoice_line == invoice_line.id
).select(table.id,
Sum(progress.effort_duration * invoice_line.unit_price),
where=where,
group_by=table.id))
for work_id, amount in cursor.fetchall():
if isinstance(amount, datetime.timedelta):
amount = amount.total_seconds()
# Amount computed in second instead of hours
if amount is not None:
amount /= 60 * 60
else:
amount = 0
amounts[work_id] = amount
cursor.execute(*table.join(company,
condition=table.company == company.id
).select(table.id, company.currency,
where=where))
work2currency.update(cursor.fetchall())
currencies = Currency.browse(set(work2currency.itervalues()))
id2currency = {c.id: c for c in currencies}
for work in works:
currency = id2currency[work2currency[work.id]]
amounts[work.id] = currency.round(Decimal(amounts[work.id]))
return amounts
示例9: table_exist
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [as 别名]
def table_exist(table_name):
cursor = Transaction().connection.cursor()
cursor.execute("SELECT sql FROM sqlite_master " "WHERE type = 'table' AND name = ?", (table_name,))
res = cursor.fetchone()
if not res:
return False
sql, = res
# Migration from 1.6 add autoincrement
if "AUTOINCREMENT" not in sql.upper():
temp_sql = sql.replace(table_name, "_temp_%s" % table_name)
cursor.execute(temp_sql)
cursor.execute('PRAGMA table_info("' + table_name + '")')
columns = ['"%s"' % column for _, column, _, _, _, _ in cursor.fetchall()]
cursor.execute(
('INSERT INTO "_temp_%s" ' "(" + ",".join(columns) + ") " "SELECT " + ",".join(columns) + ' FROM "%s"')
% (table_name, table_name)
)
cursor.execute('DROP TABLE "%s"' % table_name)
new_sql = sql.replace("PRIMARY KEY", "PRIMARY KEY AUTOINCREMENT")
cursor.execute(new_sql)
cursor.execute(
('INSERT INTO "%s" ' "(" + ",".join(columns) + ") " "SELECT " + ",".join(columns) + ' FROM "_temp_%s"')
% (table_name, table_name)
)
cursor.execute('DROP TABLE "_temp_%s"' % table_name)
return True
示例10: __register__
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [as 别名]
def __register__(cls, module_name):
pool = Pool()
Employee = pool.get('company.employee')
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = cls.__table__()
table_h = TableHandler(cursor, cls, module_name)
migrate_cost_price = not table_h.column_exist('cost_price')
super(TimesheetLine, cls).__register__(module_name)
# Migration from 3.6: add cost_price
if migrate_cost_price:
cursor.execute(*table.select(table.id, table.employee, table.date,
where=(table.cost_price == 0)
& (table.employee != Null)
& (table.date != Null)))
for line_id, employee_id, date in cursor.fetchall():
employee = Employee(employee_id)
cost_price = employee.compute_cost_price(date=date)
cursor.execute(*table.update(
[table.cost_price],
[cost_price],
where=table.id == line_id))
示例11: get_lastmodified
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [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 fetchall [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 fetchall [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: __register__
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [as 别名]
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
sql_table = cls.__table__()
pool = Pool()
Work = pool.get('timesheet.work')
work = Work.__table__()
created_company = not table.column_exist('company')
super(Line, cls).__register__(module_name)
table = TableHandler(cursor, cls, module_name)
# Migration from 3.4: new company field
if created_company:
# Don't use FROM because SQLite nor MySQL support it.
cursor.execute(*sql_table.update(
[sql_table.company], [work.select(work.company,
where=work.id == sql_table.work)]))
# Migration from 3.4: change hours into timedelta duration
if table.column_exist('hours'):
table.drop_constraint('check_move_hours_pos')
cursor.execute(*sql_table.select(
sql_table.id, sql_table.hours))
for id_, hours in cursor.fetchall():
duration = datetime.timedelta(hours=hours)
cursor.execute(*sql_table.update(
[sql_table.duration],
[duration],
where=sql_table.id == id_))
table.drop_column('hours')
示例15: _get_duration_timesheet
# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import fetchall [as 别名]
def _get_duration_timesheet(works, invoiced):
pool = Pool()
TimesheetLine = pool.get('timesheet.line')
cursor = Transaction().cursor
line = TimesheetLine.__table__()
durations = {}
twork2work = dict((w.work.id, w.id) for w in works if w.work)
ids = twork2work.keys()
for sub_ids in grouped_slice(ids):
red_sql = reduce_ids(line.work, sub_ids)
if invoiced:
where = line.invoice_line != Null
else:
where = line.invoice_line == Null
cursor.execute(*line.select(line.work, Sum(line.duration),
where=red_sql & where,
group_by=line.work))
for twork_id, duration in cursor.fetchall():
if duration:
# SQLite uses float for SUM
if not isinstance(duration, datetime.timedelta):
duration = datetime.timedelta(seconds=duration)
durations[twork2work[twork_id]] = duration
return durations