当前位置: 首页>>代码示例>>Python>>正文


Python Pool.query_get方法代码示例

本文整理汇总了Python中trytond.pool.Pool.query_get方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.query_get方法的具体用法?Python Pool.query_get怎么用?Python Pool.query_get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trytond.pool.Pool的用法示例。


在下文中一共展示了Pool.query_get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_balance_query

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import query_get [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
开发者ID:fulfilio,项目名称:trytond-report-html-accounts,代码行数:55,代码来源:report_html_accounts.py

示例2: get_move_lines_maturing

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import query_get [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
开发者ID:fulfilio,项目名称:trytond-report-html-accounts,代码行数:43,代码来源:report_html_accounts.py

示例3: read

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import query_get [as 别名]
    def read(cls, ids, fields_names=None):
        Rule = Pool().get('ir.rule')
        cursor = Transaction().cursor
        table = cls.__table__()
        if len(set(ids)) != cls.search([('id', 'in', ids)],
                count=True):
            cls.raise_user_error('access_error', cls.__doc__)

        writable_ids = []
        domain = Rule.query_get(cls.__name__, mode='write')
        if domain:
            for sub_ids in grouped_slice(ids):
                red_sql = reduce_ids(table.id, sub_ids)
                cursor.execute(*table.select(table.id,
                        where=red_sql & table.id.in_(domain)))
                writable_ids.extend(x[0] for x in cursor.fetchall())
        else:
            writable_ids = ids
        writable_ids = set(writable_ids)

        if fields_names is None:
            fields_names = []
        fields_names = fields_names[:]
        to_remove = set()
        for field in ('classification', 'calendar', 'transp'):
            if field not in fields_names:
                fields_names.append(field)
                to_remove.add(field)
        res = super(Event, cls).read(ids, fields_names=fields_names)
        for record in res:
            if record['classification'] == 'confidential' \
                    and record['id'] not in writable_ids:
                cls._clean_confidential(record, record['transp'])
            for field in to_remove:
                del record[field]
        return res
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:38,代码来源:calendar_.py

示例4: get_balance

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import query_get [as 别名]
    def get_balance(cls, accounts, name):
        res = {}
        Line = Pool().get('analytic_account.line')
        Currency = Pool().get('currency.currency')
        cursor = Transaction().cursor

        ids = [a.id for a in accounts]
        childs = cls.search([('parent', 'child_of', ids)])
        all_ids = {}.fromkeys(ids + [c.id for c in childs]).keys()

        id2account = {}
        all_accounts = cls.browse(all_ids)
        for account in all_accounts:
            id2account[account.id] = account

        line_query = Line.query_get()
        cursor.execute('SELECT a.id, '
                'SUM((COALESCE(l.debit, 0) - COALESCE(l.credit, 0))), '
                    'c.currency '
            'FROM analytic_account_account a '
                'LEFT JOIN analytic_account_line l '
                'ON (a.id = l.account) '
                'LEFT JOIN account_move_line ml '
                'ON (ml.id = l.move_line) '
                'LEFT JOIN account_account aa '
                'ON (aa.id = ml.account) '
                'LEFT JOIN company_company c '
                'ON (c.id = aa.company) '
            'WHERE a.type != \'view\' '
                'AND a.id IN (' +
                    ','.join(('%s',) * len(all_ids)) + ') '
                'AND ' + line_query + ' '
                'AND a.active '
            'GROUP BY a.id, c.currency', all_ids)
        account_sum = {}
        id2currency = {}
        for account_id, sum, currency_id in cursor.fetchall():
            account_sum.setdefault(account_id, Decimal('0.0'))
            # SQLite uses float for SUM
            if not isinstance(sum, Decimal):
                sum = Decimal(str(sum))
            if currency_id != id2account[account_id].currency.id:
                currency = None
                if currency_id in id2currency:
                    currency = id2currency[currency_id]
                else:
                    currency = Currency(currency_id)
                    id2currency[currency.id] = currency
                account_sum[account_id] += Currency.compute(currency, sum,
                        id2account[account_id].currency, round=True)
            else:
                account_sum[account_id] += \
                    id2account[account_id].currency.round(sum)

        for account_id in ids:
            res.setdefault(account_id, Decimal('0.0'))
            childs = cls.search([
                    ('parent', 'child_of', [account_id]),
                    ])
            to_currency = id2account[account_id].currency
            for child in childs:
                from_currency = id2account[child.id].currency
                res[account_id] += Currency.compute(from_currency,
                        account_sum.get(child.id, Decimal('0.0')), to_currency,
                        round=True)
            res[account_id] = to_currency.round(res[account_id])
            if id2account[account_id].display_balance == 'credit-debit':
                res[account_id] = - res[account_id]
        return res
开发者ID:silpol,项目名称:tryton-bef,代码行数:71,代码来源:account.py


注:本文中的trytond.pool.Pool.query_get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。