本文整理汇总了Python中trytond.pool.Pool.__table__方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.__table__方法的具体用法?Python Pool.__table__怎么用?Python Pool.__table__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trytond.pool.Pool
的用法示例。
在下文中一共展示了Pool.__table__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __register__
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def __register__(cls, module_name):
Party = Pool().get('party.party')
Sale = Pool().get('sale.sale')
Model = Pool().get('ir.model')
ModelField = Pool().get('ir.model.field')
Property = Pool().get('ir.property')
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
migration_needed = False
if not table.column_exist('credit_account'):
migration_needed = True
super(Payment, cls).__register__(module_name)
if migration_needed and not Pool.test:
# Migration
# Set party's receivable account as the credit_account on
# sale payments
payment = cls.__table__()
party = Party.__table__()
property = Property.__table__()
sale = Sale.__table__()
account_model, = Model.search([
('model', '=', 'party.party'),
])
account_receivable_field, = ModelField.search([
('model', '=', account_model.id),
('name', '=', 'account_receivable'),
('ttype', '=', 'many2one'),
])
update = payment.update(
columns=[payment.credit_account],
values=[
Trim(
Substring(property.value, ',.*'), 'LEADING', ','
).cast(cls.credit_account.sql_type().base)
],
from_=[sale, party, property],
where=(
payment.sale == sale.id
) & (
sale.party == party.id
) & (
property.res == Concat(Party.__name__ + ',', party.id)
) & (
property.field == account_receivable_field.id
) & (
property.company == sale.company
)
)
cursor.execute(*update)
示例2: _get_balance_query
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def _get_balance_query(self, end_date,
start_date=None, unreconciled_lines_only=True):
"""
Returns a python-sql object that can be used to query the move tables.
Does not select anything in the query and leaves it to the programmer
calling this api.
"""
MoveLine = Pool().get('account.move.line')
Account = Pool().get('account.account')
Move = Pool().get('account.move')
User = Pool().get('res.user')
line = MoveLine.__table__()
account = Account.__table__()
move = Move.__table__()
user_id = Transaction().user
if user_id == 0 and 'user' in Transaction().context:
user_id = Transaction().context['user']
user = User(user_id)
if not user.company:
return _ZERO
company_id = user.company.id
line_query, _ = MoveLine.query_get(line)
date_where = (move.date <= end_date)
if start_date is not None:
date_where &= (move.date >= start_date)
tables = {
'account.move.line': line,
'account.account': account,
'account.move': move,
}
query = line.join(
account,
condition=account.id == line.account
).join(
move,
condition=line.move == move.id
).select(
where=account.active &
(account.kind.in_(('receivable', 'payable'))) &
(line.party == self.id) &
(account.company == company_id) &
line_query &
date_where
)
if unreconciled_lines_only:
query.where &= (line.reconciliation == None) # noqa
return query, tables
示例3: __register__
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [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')
示例4: get_creationdate
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def get_creationdate(cls, uri, cache=None):
Party = Pool().get('party.party')
party = Party.__table__()
party_id = cls.vcard(uri)
cursor = Transaction().cursor
if party_id is None:
raise DAV_NotFound
if party_id:
if cache is not None:
cache.setdefault('_contact', {})
ids = cache['_contact'].keys()
if party_id not in ids:
ids.append(party_id)
elif 'creationdate' in cache['_contact'][party_id]:
return cache['_contact'][party_id]['creationdate']
else:
ids = [party_id]
res = None
for sub_ids in grouped_slice(ids):
red_sql = reduce_ids(party.id, sub_ids)
cursor.execute(*party.select(party.id,
Extract('EPOCH', party.create_date),
where=red_sql))
for party_id2, date in cursor.fetchall():
if party_id2 == party_id:
res = date
if cache is not None:
cache['_contact'].setdefault(party_id2, {})
cache['_contact'][party_id2]['creationdate'] = date
if res is not None:
return res
return super(Collection, cls).get_creationdate(uri, cache=cache)
示例5: merge_into
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def merge_into(self, target):
"""Merge current record to target party.
"""
ModelField = Pool().get('ir.model.field')
# Inactive party first
self.active = False
self.save()
cursor = Transaction().connection.cursor()
if self._history:
# Update the party history first.
#
# The approach is to make the history of all merged records
# also the history of the target record.
party_history_table = self.__table_history__()
cursor.execute(
*party_history_table.update(
columns=[party_history_table.id],
values=[target.id],
where=(party_history_table.id == self.id)
)
)
party_fields = ModelField.search([
('relation', '=', 'party.party'),
('ttype', '=', 'many2one'),
])
for field in party_fields:
Model = Pool().get(field.model.model)
if isinstance(getattr(Model, field.name), fields.Function):
continue
if not hasattr(Model, '__table__'):
continue
if Model.table_query():
continue
sql_table = Model.__table__()
# Update direct foreign key references
cursor.execute(*sql_table.update(
columns=[getattr(sql_table, field.name)], values=[target.id],
where=(getattr(sql_table, field.name) == self.id)
))
if Model._history:
# If historization is enabled on the model
# then the party value in the history should
# now point to the target party id since the
# history of the current party is already the history of
# target party.
history_table = Model.__table_history__()
cursor.execute(*history_table.update(
columns=[getattr(history_table, field.name)],
values=[target.id],
where=(getattr(history_table, field.name) == self.id)
))
示例6: get_move_lines_maturing
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def get_move_lines_maturing(cls, party, start_date, end_date):
"""
Returns the move lines maturing in the given date range
"""
AccountMoveLines = Pool().get('account.move.line')
AccountMove = Pool().get('account.move')
User = Pool().get('res.user')
Account = Pool().get('account.account')
user = User(Transaction().user)
cursor = Transaction().connection.cursor()
line = AccountMoveLines.__table__()
move = AccountMove.__table__()
account = Account.__table__()
line_query, _ = AccountMoveLines.query_get(line)
sub_query = line.join(
account,
condition=account.id == line.account
)
query = sub_query.join(
move,
condition=line.move == move.id,
).select(
line.id,
where=account.active &
(line.party == party.id) &
(account.company == user.company.id) &
(account.kind.in_(('receivable', 'payable'))) &
(line.maturity_date >= start_date) &
(line.maturity_date <= end_date) &
line_query,
order_by=move.date.asc
)
cursor.execute(*query)
move_line_ids = [id[0] for id in cursor.fetchall()]
move_lines = AccountMoveLines.browse(move_line_ids)
return move_lines
示例7: __register__
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().connection.cursor()
ContactMech = Pool().get('party.contact_mechanism')
sql_table = cls.__table__()
contact_mech_table = ContactMech.__table__()
super(Address, cls).__register__(module_name)
table = TableHandler(cls, module_name)
if table.column_exist('phone_number'):
cursor.execute(*sql_table.update(
columns=[sql_table.phone],
values=[contact_mech_table.value],
from_=[contact_mech_table],
where=sql_table.phone_number == contact_mech_table.id)
)
table.column_rename("phone_number", "phone_number_deprecated")
示例8: get_lastmodified
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def get_lastmodified(cls, uri, cache=None):
Todo = Pool().get('calendar.todo')
todo = Todo.__table__()
cursor = Transaction().cursor
calendar_id = cls.calendar(uri)
if calendar_id and (uri[10:].split('/', 1) + [None])[1]:
todo_id = cls.todo(uri, calendar_id=calendar_id)
if todo_id:
if cache is not None:
cache.setdefault('_calendar', {})
cache['_calendar'].setdefault(Todo.__name__, {})
ids = cache['_calendar'][Todo.__name__].keys()
if todo_id not in ids:
ids.append(todo_id)
elif 'lastmodified' in cache['_calendar'][
Todo.__name__][todo_id]:
return cache['_calendar'][Todo.__name__][
todo_id]['lastmodified']
else:
ids = [todo_id]
res = None
for sub_ids in grouped_slice(ids, cursor.IN_MAX / 2):
red_id_sql = reduce_ids(todo.id, sub_ids)
red_parent_sql = reduce_ids(todo.parent, sub_ids)
cursor.execute(*todo.select(Coalesce(todo.parent, todo.id),
Max(Extract('EPOCH', Coalesce(todo.write_date,
todo.create_date))),
where=red_id_sql | red_parent_sql,
group_by=(todo.parent, todo.id)))
for todo_id2, date in cursor.fetchall():
if todo_id2 == todo_id:
res = date
if cache is not None:
cache['_calendar'][Todo.__name__]\
.setdefault(todo_id2, {})
cache['_calendar'][Todo.__name__][
todo_id2]['lastmodified'] = date
if res is not None:
return res
return super(Collection, cls).get_lastmodified(uri, cache=cache)
示例9: get_recent_sales
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def get_recent_sales(cls):
"""
Return sales of current channel, which were made within last 5 days
and are in draft state. Sort by write_date or create_date of Sale and
sale lines.
"""
SaleLine = Pool().get('sale.line')
context = Transaction().context
date = (
datetime.now() - timedelta(days=5)
).strftime('%Y-%m-%d %H:%M:%S')
current_channel = context['current_channel']
SaleTable = cls.__table__()
SaleLineTable = SaleLine.__table__()
cursor = Transaction().cursor
query = SaleTable.join(
SaleLineTable,
condition=(SaleTable.id == SaleLineTable.sale)
).select(
SaleTable.id,
where=(
(SaleTable.channel == Literal(current_channel)) &
(SaleTable.state.in_([
'draft', 'quotation', 'confirmed', 'processing'
])) &
(
(SaleTable.write_date >= Literal(date)) |
(SaleTable.create_date >= Literal(date))
)
),
order_by=(
SaleLineTable.write_date.desc,
SaleLineTable.create_date.desc,
SaleTable.write_date.desc,
SaleTable.create_date.desc
)
)
cursor.execute(*query)
ids = [x[0] for x in cursor.fetchall()]
return [cls(id).serialize('recent_sales') for id in ids]
示例10: __register__
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def __register__(cls, module_name):
Identifier = Pool().get('party.identifier')
cursor = Transaction().connection.cursor()
sql_table = cls.__table__()
identifier = Identifier.__table__()
super(Party, cls).__register__(module_name)
table = cls.__table_handler__(module_name)
# Migration from 4.0: Move sepa_creditor_identifier to identifier
if table.column_exist('sepa_creditor_identifier'):
select = sql_table.select(Literal(0), CurrentTimestamp(),
sql_table.id, Literal('sepa'),
sql_table.sepa_creditor_identifier,
where=((sql_table.sepa_creditor_identifier != Null)
& (sql_table.sepa_creditor_identifier != "")))
cursor.execute(*identifier.insert(
columns=[identifier.create_uid, identifier.create_date,
identifier.party, identifier.type, identifier.code],
values=select))
table.drop_column('sepa_creditor_identifier')
示例11: __register__
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
Article = Pool().get('nereid.cms.article')
table = TableHandler(cursor, Article, module_name)
# Move data from category to categories
if table.column_exist('category'):
article = Article.__table__()
article_categ_rel = cls.__table__()
article_select = article.select(article.id, article.category)
cursor.execute(*article_categ_rel.insert(
columns=[article_categ_rel.article, article_categ_rel.category],
values=article_select
))
table.drop_column('category')
super(ArticleCategoryRelation, cls).__register__(module_name)
示例12: search_patient_status
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def search_patient_status(cls, name, clause):
p = Pool().get('gnuhealth.inpatient.registration')
table = p.__table__()
pat = cls.__table__()
_, operator, value = clause
# Validate operator and value
if operator not in ['=', '!=']:
raise ValueError('Wrong operator: %s' % operator)
if value is not True and value is not False:
raise ValueError('Wrong value: %s' % value)
# Find hospitalized patient ids
j = pat.join(table, condition = pat.id == table.patient)
s = j.select(pat.id, where = table.state == 'hospitalized')
# Choose domain operator
if (operator == '=' and value) or (operator == '!=' and not value):
d = 'in'
else:
d = 'not in'
return [('id', d, s)]
示例13: table_query
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def table_query(cls):
Opportunity = Pool().get('sale.opportunity')
opportunity = Opportunity.__table__()
return opportunity.select(
Max(opportunity.create_uid).as_('create_uid'),
Max(opportunity.create_date).as_('create_date'),
Max(opportunity.write_uid).as_('write_uid'),
Max(opportunity.write_date).as_('write_date'),
opportunity.company,
Count(Literal(1)).as_('number'),
Sum(Case((opportunity.state.in_(cls._converted_state()),
Literal(1)), else_=Literal(0))).as_('converted'),
Sum(Case((opportunity.state.in_(cls._won_state()),
Literal(1)), else_=Literal(0))).as_('won'),
Sum(Case((opportunity.state.in_(cls._lost_state()),
Literal(1)), else_=Literal(0))).as_('lost'),
Sum(opportunity.amount).as_('amount'),
Sum(Case((opportunity.state.in_(cls._converted_state()),
opportunity.amount),
else_=Literal(0))).as_('converted_amount'),
Sum(Case((opportunity.state.in_(cls._won_state()),
opportunity.amount),
else_=Literal(0))).as_('won_amount'))
示例14: __register__
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def __register__(cls, module_name):
super(Party, cls).__register__(module_name)
PaymentProfile = Pool().get('party.payment_profile')
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
party = cls.__table__()
payment_profile = PaymentProfile.__table__()
# Migration
# Move the content of authorize_profile_id from party to
# payment profiles and drop authorize_profile_id from party table
if table.column_exist('authorize_profile_id'):
update = payment_profile.update(
columns=[payment_profile.authorize_profile_id],
values=[party.authorize_profile_id],
from_=[party],
where=(payment_profile.party == party.id)
)
cursor.execute(*update)
table.drop_column('authorize_profile_id')
示例15: _get_products
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import __table__ [as 别名]
def _get_products(self):
"""
Return a query based on the node settings. This is separated for
easy subclassing. The returned value would be a tuple with the
dollowing elements:
* The Model instance
* Select query instance
* The Table instance for the SQL Pagination
"""
Node = Pool().get('product.tree_node')
Product = Pool().get('product.product')
ProductTemplate = Pool().get('product.template')
ProductNodeRelation = Pool().get('product.product-product.tree_node')
ProductTable = Product.__table__()
TemplateTable = ProductTemplate.__table__()
RelTable = ProductNodeRelation.__table__()
NodeTable = Node.__table__()
if self.display == 'product.product':
query = ProductTable.join(
TemplateTable,
condition=(TemplateTable.id == ProductTable.template)
).join(
RelTable,
condition=(RelTable.product == ProductTable.id)
).join(
NodeTable,
condition=(RelTable.node == NodeTable.id)
).select(
where=(
TemplateTable.active &
ProductTable.displayed_on_eshop &
ProductTable.active &
(NodeTable.left >= Literal(self.left)) &
(NodeTable.right <= Literal(self.right))
),
order_by=RelTable.sequence.asc
)
return Product, query, ProductTable
elif self.display == 'product.template':
query = TemplateTable.join(
ProductTable,
condition=(TemplateTable.id == ProductTable.template)
).join(
RelTable,
condition=(RelTable.product == ProductTable.id)
).join(
NodeTable,
condition=(RelTable.node == NodeTable.id)
).select(
where=(
TemplateTable.active &
ProductTable.displayed_on_eshop &
ProductTable.active &
(NodeTable.left >= Literal(self.left)) &
(NodeTable.right <= Literal(self.right))
),
order_by=RelTable.sequence.asc
)
return ProductTemplate, query, TemplateTable