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


Python Pool.get方法代码示例

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


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

示例1: get_quantity

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
    def get_quantity(cls, locations, name):
        pool = Pool()
        Product = pool.get("product.product")
        Date_ = pool.get("ir.date")

        if (not Transaction().context.get("product")) or not (
            isinstance(Transaction().context["product"], (int, long))
        ):
            return dict([(l.id, 0) for l in locations])

        with Transaction().set_context(active_test=False):
            if not Product.search([("id", "=", Transaction().context["product"])]):
                return dict([(l.id, 0) for l in locations])

        context = {}
        if name == "quantity" and Transaction().context.get("stock_date_end") > Date_.today():
            context["stock_date_end"] = Date_.today()

        if name == "forecast_quantity":
            context["forecast"] = True
            if not Transaction().context.get("stock_date_end"):
                context["stock_date_end"] = datetime.date.max

        location_ids = [l.id for l in locations]
        product_id = Transaction().context["product"]
        with Transaction().set_context(context):
            pbl = Product.products_by_location(location_ids=location_ids, product_ids=[product_id], with_childs=True)

        return dict((loc, pbl.get((loc, product_id), 0)) for loc in location_ids)
开发者ID:ferjavrec,项目名称:stock,代码行数:31,代码来源:location.py

示例2: close

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
    def close(cls, fiscalyears):
        '''
        Close a fiscal year
        '''
        pool = Pool()
        Period = pool.get('account.period')
        Account = pool.get('account.account')

        for fiscalyear in fiscalyears:
            if cls.search([
                        ('end_date', '<=', fiscalyear.start_date),
                        ('state', '=', 'open'),
                        ('company', '=', fiscalyear.company.id),
                        ]):
                cls.raise_user_error('close_error', (fiscalyear.rec_name,))

            #First close the fiscalyear to be sure
            #it will not have new period created between.
            cls.write([fiscalyear], {
                'state': 'close',
                })
            periods = Period.search([
                    ('fiscalyear', '=', fiscalyear.id),
                    ])
            Period.close(periods)

            with Transaction().set_context(fiscalyear=fiscalyear.id,
                    date=None, cumulate=True):
                accounts = Account.search([
                        ('company', '=', fiscalyear.company.id),
                        ])
            for account in accounts:
                fiscalyear._process_account(account)
开发者ID:Sisouvan,项目名称:ogh,代码行数:35,代码来源:fiscalyear.py

示例3: do_open

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
    def do_open(self, action):
        pool = Pool()
        Location = pool.get('stock.location')
        Lang = pool.get('ir.lang')

        context = {}
        context['locations'] = Transaction().context.get('active_ids')
        date = self.start.forecast_date or datetime.date.max
        context['stock_date_end'] = Date(date.year, date.month, date.day)
        action['pyson_context'] = PYSONEncoder().encode(context)

        locations = Location.browse(context['locations'])

        for code in [Transaction().language, 'en_US']:
            langs = Lang.search([
                    ('code', '=', code),
                    ])
            if langs:
                break
        lang = langs[0]
        date = Lang.strftime(date, lang.code, lang.date)

        action['name'] += ' - (%s) @ %s' % (
            ','.join(l.name for l in locations), date)
        return action, {}
开发者ID:aleibrecht,项目名称:tryton-modules-ar,代码行数:27,代码来源:location.py

示例4: get_move

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
    def get_move(self, line):
        """
        Return the account.move generated by an asset line.
        """
        pool = Pool()
        Period = pool.get('account.period')
        Move = pool.get('account.move')
        MoveLine = pool.get('account.move.line')

        period_id = Period.find(self.company.id, line.date)
        with Transaction().set_user(0, set_context=True):
            expense_line = MoveLine(
                credit=0,
                debit=line.depreciation,
                account=self.product.account_expense_used,
                )
            depreciation_line = MoveLine(
                debit=0,
                credit=line.depreciation,
                account=self.product.account_depreciation_used,
                )

            return Move(
                origin=line,
                period=period_id,
                journal=self.account_journal,
                date=line.date,
                lines=[expense_line, depreciation_line],
                )
开发者ID:silpol,项目名称:tryton-bef,代码行数:31,代码来源:asset.py

示例5: create_move

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
    def create_move(self):
        pool = Pool()
        Account = pool.get('account.account')
        Move = pool.get('account.move')

        with Transaction().set_context(fiscalyear=self.start.fiscalyear.id,
                date=None, cumulate=False):
            accounts = Account.search([
                    ('company', '=', self.start.fiscalyear.company.id),
                    ('deferral', '=', False),
                    ('kind', '!=', 'view'),
                    ])
        lines = []
        for account in accounts:
            line = self.get_move_line(account)
            if line:
                lines.append(line)
        if not lines:
            return
        amount = sum(l.debit - l.credit for l in lines)
        counter_part_line = self.get_counterpart_line(amount)
        if counter_part_line:
            lines.append(counter_part_line)

        move = Move()
        move.period = self.start.period
        move.journal = self.start.journal
        move.date = self.start.period.start_date
        move.origin = self.start.fiscalyear
        move.lines = lines
        move.save()
        return move
开发者ID:aleibrecht,项目名称:tryton-modules-ar,代码行数:34,代码来源:fiscalyear.py

示例6: test_get_tariff_code

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
    def test_get_tariff_code(self):
        'Test get_tariff_code'
        pool = Pool()
        Tariff = pool.get('customs.tariff.code')
        Template = pool.get('product.template')
        Category = pool.get('product.category')
        Product_TariffCode = pool.get(
            'product-customs.tariff.code')

        tariff1, tariff2, tariff3 = Tariff.create([
                {'code': '170390'},
                {'code': '17039099'},
                {'code': '1703909999'},
                ])

        category1 = Category(tariff_codes=[
                Product_TariffCode(tariff_code=tariff1),
                ], tariff_codes_parent=False)
        category2 = Category(tariff_codes=[
                Product_TariffCode(tariff_code=tariff2),
                ], parent=category1, tariff_codes_parent=False)
        template = Template(tariff_codes=[
                Product_TariffCode(tariff_code=tariff3),
                ], category=category2, tariff_codes_category=False)

        self.assertEqual(template.get_tariff_code({}), tariff3)

        template.tariff_codes_category = True
        self.assertEqual(template.get_tariff_code({}), tariff2)

        category2.tariff_codes_parent = True
        self.assertEqual(template.get_tariff_code({}), tariff1)
开发者ID:kret0s,项目名称:tryton3_8,代码行数:34,代码来源:test_customs.py

示例7: get_expenses

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
    def get_expenses(self):
        pool = Pool()
        Date = pool.get('ir.date')
        AccountType = pool.get('account.account.type')    
        today = Date.today()
        transaction = Transaction()
        context = Transaction().context
        total_expense = expense = Decimal('0.0')

        if self.is_consolidated: 
            companies = context.get('companies',[])
            for company in context.get('companies', []):
                with transaction.set_context(company=company['id']):
                    expense = Decimal('0.0')
                    expenses = AccountType.search([('company','=',company['id']),
                        ('name','=','GASTOS FINANCIEROS')
                        ])
                    if len(expenses)==1: 
                        expense = expenses[0].amount * Decimal('1.0')
                total_expense += expense
            return total_expense
        else:
            company = Transaction().context.get('company')
            expense = Decimal('0.0') 
            expenses = AccountType.search([('company','=',company),
                ('name','=','GASTOS FINANCIEROS')])
            
            if len(expenses)==1: 
                expense = expenses[0].amount * Decimal('1.0')
            
        return expense
开发者ID:iehoshia,项目名称:training_iesa,代码行数:33,代码来源:account.py

示例8: write

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
    def write(cls, *args):
        pool = Pool()
        Purchase = pool.get('purchase.purchase')
        PurchaseLine = pool.get('purchase.line')

        super(ShipmentIn, cls).write(*args)

        actions = iter(args)
        for shipments, values in zip(actions, actions):
            if values.get('state') not in ('received', 'cancel'):
                continue
            purchases = []
            move_ids = []
            for shipment in shipments:
                move_ids.extend([x.id for x in shipment.incoming_moves])

            purchase_lines = PurchaseLine.search([
                    ('moves', 'in', move_ids),
                    ])
            if purchase_lines:
                for purchase_line in purchase_lines:
                    if purchase_line.purchase not in purchases:
                        purchases.append(purchase_line.purchase)

            with Transaction().set_context(_check_access=False):
                purchases = Purchase.browse([p.id for p in purchases])
                Purchase.process(purchases)
开发者ID:aleibrecht,项目名称:tryton-modules-ar,代码行数:29,代码来源:stock.py

示例9: set_account

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
 def set_account(cls, configurations, name, value):
     pool = Pool()
     Property = pool.get('ir.property')
     ModelField = pool.get('ir.model.field')
     company_id = Transaction().context.get('company')
     model = 'party.party'
     if name == 'default_hat_account':
         model = 'artist'
     account_field, = ModelField.search(
         [
             ('model.model', '=', model),
             ('name', '=', name[8:]),
         ], limit=1)
     properties = Property.search(
         [
             ('field', '=', account_field.id),
             ('res', '=', None),
             ('company', '=', company_id),
         ])
     Property.delete(properties)
     if value:
         Property.create(
             [
                 {
                     'field': account_field.id,
                     'value': 'account.account,%s' % value,
                     'company': company_id,
                 }])
开发者ID:C3S,项目名称:collecting_society,代码行数:30,代码来源:configuration.py

示例10: set_action

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
 def set_action(cls, menus, name, value):
     if not value:
         return
     pool = Pool()
     ActionKeyword = pool.get("ir.action.keyword")
     action_keywords = []
     cursor = Transaction().cursor
     for i in range(0, len(menus), cursor.IN_MAX):
         sub_menus = menus[i : i + cursor.IN_MAX]
         action_keywords += ActionKeyword.search(
             [("keyword", "=", "tree_open"), ("model", "in", [str(menu) for menu in sub_menus])]
         )
     if action_keywords:
         with Transaction().set_context(_timestamp=False):
             ActionKeyword.delete(action_keywords)
     if isinstance(value, basestring):
         action_type, action_id = value.split(",")
     else:
         action_type, action_id = value
     if not int(action_id):
         return
     Action = pool.get(action_type)
     action = Action(int(action_id))
     to_create = []
     for menu in menus:
         with Transaction().set_context(_timestamp=False):
             to_create.append({"keyword": "tree_open", "model": str(menu), "action": action.action.id})
     if to_create:
         ActionKeyword.create(to_create)
开发者ID:silpol,项目名称:tryton-bef,代码行数:31,代码来源:menu.py

示例11: get_account

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
 def get_account(self, name):
     pool = Pool()
     Property = pool.get('ir.property')
     ModelField = pool.get('ir.model.field')
     company_id = Transaction().context.get('company')
     model = 'party.party'
     if name == 'default_hat_account':
         model = 'artist'
     account_field = ModelField.search(
         [
             ('model.model', '=', model),
             ('name', '=', name[8:]),
         ], limit=1)
     if not account_field:
         return None
     account_field = account_field[0]
     properties = Property.search(
         [
             ('field', '=', account_field.id),
             ('res', '=', None),
             ('company', '=', company_id),
         ], limit=1)
     if properties:
         prop, = properties
         return prop.value.id
开发者ID:C3S,项目名称:collecting_society,代码行数:27,代码来源:configuration.py

示例12: restore_default_party_lang_from_4_2

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [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')
开发者ID:coopengo,项目名称:party,代码行数:35,代码来源:configuration.py

示例13: test_get_anglo_saxon_move

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
    def test_get_anglo_saxon_move(self):
        'Test _get_anglo_saxon_move'
        pool = Pool()
        Move = pool.get('stock.move')
        Uom = pool.get('product.uom')
        Currency = pool.get('currency.currency')

        def move(quantity, price):
            move = Mock()
            move.quantity = quantity
            move.unit_price = price
            move.cost_price = price
            move.in_anglo_saxon_quantity = 0
            move.out_anglo_saxon_quantity = 0
            return move

        with patch.object(Uom, 'compute_qty') as compute_qty, \
                patch.object(Uom, 'compute_price') as compute_price, \
                patch.object(Currency, 'compute') as compute:
            compute_qty.side_effect = lambda *args, **kwargs: args[1]
            compute_price.side_effect = lambda *args, **kwargs: args[1]
            compute.side_effect = lambda *args, **kwargs: args[1]

            moves = [move(1, 3), move(2, 2)]
            result = list(Move._get_anglo_saxon_move(
                    moves, 1, 'in_supplier'))
            self.assertEqual(result, [(moves[0], 1, 3)])

            moves = [move(1, 3), move(2, 2)]
            result = list(Move._get_anglo_saxon_move(
                    moves, 2, 'in_supplier'))
            self.assertEqual(result,
                [(moves[0], 1, 3), (moves[1], 1, 2)])
开发者ID:kret0s,项目名称:tryton3_8,代码行数:35,代码来源:test_account_stock_anglo_saxon.py

示例14: default_currency

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
    def default_currency():
        pool = Pool()
        Company = pool.get('company.company')
        Channel = pool.get('sale.channel')

        company_id = Channel.default_company()
        return company_id and Company(company_id).currency.id
开发者ID:prakashpp,项目名称:trytond-sale-channel,代码行数:9,代码来源:channel.py

示例15: test_menu_action

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get [as 别名]
    def test_menu_action(self):
        'Test that menu actions are accessible to menu\'s group'
        with Transaction().start(DB_NAME, USER, context=CONTEXT):
            pool = Pool()
            Menu = pool.get('ir.ui.menu')
            ModelData = pool.get('ir.model.data')

            module_menus = ModelData.search([
                    ('model', '=', 'ir.ui.menu'),
                    ('module', '=', self.module),
                    ])
            menus = Menu.browse([mm.db_id for mm in module_menus])
            for menu, module_menu in zip(menus, module_menus):
                if not menu.action_keywords:
                    continue
                menu_groups = set(menu.groups)
                actions_groups = reduce(operator.or_,
                    (set(k.action.groups) for k in menu.action_keywords
                        if k.keyword == 'tree_open'))
                if not actions_groups:
                    continue
                assert menu_groups <= actions_groups, (
                    'Menu "%(menu_xml_id)s" actions are not accessible to '
                    '%(groups)s' % {
                        'menu_xml_id': module_menu.fs_id,
                        'groups': ','.join(g.name
                            for g in menu_groups - actions_groups),
                        })
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:30,代码来源:test_tryton.py


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