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


Python tools.reduce_ids函数代码示例

本文整理汇总了Python中trytond.tools.reduce_ids函数的典型用法代码示例。如果您正苦于以下问题:Python reduce_ids函数的具体用法?Python reduce_ids怎么用?Python reduce_ids使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test0020reduce_ids_one_hole

 def test0020reduce_ids_one_hole(self):
     '''
     Test reduce_ids continue list with one hole.
     '''
     self.assert_(('(((id >= %s) AND (id <= %s)) OR '
             '((id >= %s) AND (id <= %s)))', [0, 9, 20, 29])
         == reduce_ids('id', range(10) + map(lambda x: x + 20, range(10))))
开发者ID:Sisouvan,项目名称:ogh,代码行数:7,代码来源:test_tools.py

示例2: __register__

    def __register__(cls, module_name):
        pool = Pool()
        StatementLine = pool.get('account.statement.line')
        cursor = Transaction().connection.cursor()
        sql_table = cls.__table__()

        super(Move, cls).__register__(module_name)

        # Migration from 3.4:
        # account.statement.line origin changed to account.statement
        statement_line = StatementLine.__table__()
        cursor.execute(*sql_table.join(statement_line,
                condition=(
                    Concat(StatementLine.__name__ + ',', statement_line.id)
                    == sql_table.origin
                    )
                ).select(sql_table.id, statement_line.statement,
                order_by=(sql_table.id, statement_line.statement)))
        for statement_id, values in groupby(cursor.fetchall(), itemgetter(1)):
            ids = [x[0] for x in values]
            for sub_ids in grouped_slice(ids):
                red_sql = reduce_ids(sql_table.id, sub_ids)
                cursor.execute(*sql_table.update(
                        columns=[sql_table.origin],
                        values=['account.statement,%s' % statement_id],
                        where=red_sql))
开发者ID:coopengo,项目名称:account_statement,代码行数:26,代码来源:account.py

示例3: generate

    def generate(cls, pains):
        pool = Pool()
        Payment = pool.get('condo.payment')
        payment = Payment.__table__()
        cursor = Transaction().connection.cursor()

        for pain in pains:
            pids = [p.id for group in pain.groups for p in group.payments]
            for sub_ids in grouped_slice(pids):
                red_sql = reduce_ids(payment.id, sub_ids)

                cursor.execute(*payment.update(
                        columns=[payment.state],
                        values=['approved'],
                        where=red_sql))
            try:
                tmpl = pain.get_sepa_template()
                message = tmpl.generate(pain=pain,
                    datetime=datetime, normalize=unicodedata.normalize,
                    ).filter(remove_comment).render()
                pain.message = message

                pain.save()
            except:
                Transaction().rollback()
                cls.raise_user_error('generate_error', (pain.reference,pain.company.party.name))
            else:
                Transaction().commit()
开发者ID:malonp,项目名称:trytond-condominium_payment_sepa,代码行数:28,代码来源:payment.py

示例4: get_lastmodified

 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()
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:35,代码来源:webdav.py

示例5: get_creationdate

 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()
开发者ID:Sisouvan,项目名称:ogh,代码行数:35,代码来源:webdav.py

示例6: get_creationdate

    def get_creationdate(cls, uri, cache=None):
        Party = Pool().get('party.party')
        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 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 "' + Party._table + '" '
                    'WHERE ' + red_sql, red_ids)
                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)
开发者ID:silpol,项目名称:tryton-bef,代码行数:35,代码来源:webdav.py

示例7: _get_balance_query

 def _get_balance_query(cls, sub_ids):
     pool = Pool()
     Budget = pool.get('account.budget')
     BudgetAccount = pool.get('account.budget-account.account')
     Move = pool.get('account.move')
     MoveLine = pool.get('account.move.line')
     table = cls.__table__()
     table_a = Budget.__table__()
     table_c = Budget.__table__()
     account = BudgetAccount.__table__()
     move = Move.__table__()
     line = MoveLine.__table__()
     balance = Sum(Coalesce(line.credit, 0) - Coalesce(line.debit, 0)) 
     return table.join(table_a,
         condition=(table_a.id == table.budget)
         ).join(table_c,
         condition=(table_c.left >= table_a.left)
         & (table_c.right <= table_a.right)
         ).join(account, condition=account.budget == table_c.id
         ).join(line, condition=line.account == account.account
         ).join(move, condition=((move.id == line.move)
             & (move.period == table.period))).select(
         table.id, balance,
         where=reduce_ids(table.id, sub_ids),
         group_by=table.id)
开发者ID:iehoshia,项目名称:training_iesa,代码行数:25,代码来源:budget.py

示例8: get_pending_amount

    def get_pending_amount(cls, agents, name):
        pool = Pool()
        Commission = pool.get('commission')
        commission = Commission.__table__()
        cursor = Transaction().connection.cursor()

        ids = [a.id for a in agents]
        amounts = dict.fromkeys(ids, None)
        for sub_ids in grouped_slice(ids):
            where = reduce_ids(commission.agent, sub_ids)
            where &= commission.invoice_line == Null
            query = commission.select(commission.agent, Sum(commission.amount),
                where=where,
                group_by=commission.agent)
            cursor.execute(*query)
            amounts.update(dict(cursor.fetchall()))
        digits = cls.pending_amount.digits
        exp = Decimal(str(10.0 ** -digits[1]))
        for agent_id, amount in amounts.items():
            if amount:
                # SQLite uses float for SUM
                if not isinstance(amount, Decimal):
                    amount = Decimal(str(amount))
                amounts[agent_id] = amount.quantize(exp)
        return amounts
开发者ID:coopengo,项目名称:commission,代码行数:25,代码来源:commission.py

示例9: get_creationdate

    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)
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:34,代码来源:webdav.py

示例10: _get_duration_timesheet

    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
开发者ID:kret0s,项目名称:tryton3_8,代码行数:25,代码来源:work.py

示例11: validate_active

    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))
开发者ID:malonp,项目名称:trytond-condominium_payment_sepa,代码行数:30,代码来源:payment.py

示例12: get_lastmodified

    def get_lastmodified(cls, uri, cache=None):
        Todo = Pool().get('calendar.todo')

        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 i in range(0, len(ids), cursor.IN_MAX / 2):
                    sub_ids = ids[i:i + cursor.IN_MAX / 2]
                    red_id_sql, red_id_ids = reduce_ids('id', sub_ids)
                    red_parent_sql, red_parent_ids = reduce_ids('parent',
                            sub_ids)
                    cursor.execute('SELECT COALESCE(parent, id), '
                            'MAX(EXTRACT(epoch FROM '
                            'COALESCE(write_date, create_date))) '
                        'FROM "' + Todo._table + '" '
                        'WHERE ' + red_id_sql + ' '
                            'OR ' + red_parent_sql + ' '
                        'GROUP BY parent, id', red_id_ids + red_parent_ids)
                    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)
开发者ID:silpol,项目名称:tryton-bef,代码行数:46,代码来源:webdav.py

示例13: test_reduce_ids_float

 def test_reduce_ids_float(self):
     'Test reduce_ids with integer as float'
     self.assertEqual(reduce_ids(self.table.id,
             [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0,
                 15.0, 18.0, 19.0, 21.0]),
         (((self.table.id >= 1.0) & (self.table.id <= 12.0))
             | (self.table.id.in_([15.0, 18.0, 19.0, 21.0]))))
     self.assertRaises(AssertionError, reduce_ids, self.table.id, [1.1])
开发者ID:coopengo,项目名称:trytond,代码行数:8,代码来源:test_tools.py

示例14: test0040reduce_ids_complex

 def test0040reduce_ids_complex(self):
     '''
     Test reduce_ids complex list.
     '''
     self.assertEqual(('(((id >= %s) AND (id <= %s)) OR '
             '(id IN (%s,%s,%s,%s,%s)))', [0, 14, 25, 26, 27, 28, 29]),
         reduce_ids('id', range(10) + map(lambda x: x + 25, range(5))
             + map(lambda x: x + 5, range(10))))
开发者ID:Sisouvan,项目名称:ogh,代码行数:8,代码来源:test_tools.py

示例15: test0050reduce_ids_complex_small_continue

 def test0050reduce_ids_complex_small_continue(self):
     '''
     Test reduce_ids complex list with small continue.
     '''
     self.assertEqual(('(((id >= %s) AND (id <= %s)) '
             'OR (id IN (%s,%s,%s,%s)))', [1, 12, 15, 18, 19, 21]),
         reduce_ids('id', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 18,
                 19, 21]))
开发者ID:Sisouvan,项目名称:ogh,代码行数:8,代码来源:test_tools.py


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