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


Python Transaction.set_context方法代码示例

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


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

示例1: get_current_liability

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

        company = Transaction().context.get('company')
        to_date = Transaction().context.get('to_date')

        if self.is_consolidated: 
            companies = context.get('companies',[])
            date = today if to_date is None else to_date
            for company in context.get('companies', []):
                with transaction.set_context(company=company['id'],
                        posted=True, 
                        cumulate=True, 
                        date=date, 
                        to_date=date, 
                        from_date=None,
                    ):
                    liability = Decimal('0.0')
                    liabilities = AccountType.search([('company','=',company['id']),
                        ('name','=','3) PASIVOS CORRIENTES')
                        ])
                    if len(liabilities)==1: 
                        liability = liabilities[0].amount * Decimal('1.0')
                total_liability += liability
            return total_liability
        else:
            current_liability = Decimal('0.0') 
            date = today if to_date is None else to_date
            with transaction.set_context(
                    posted=True, 
                    cumulate=True, 
                    date=date, 
                    to_date=date, 
                    from_date=None, 
                    ):
                current_liabilities = AccountType.search([('company','=',company),
                    ('name','=','3) PASIVOS CORRIENTES')])
                if len(current_liabilities)==1: 
                    current_liability = current_liabilities[0].amount * Decimal('1.0')
            
        return current_liability
开发者ID:iehoshia,项目名称:training_iesa,代码行数:50,代码来源:account.py

示例2: get_cash

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

        today = Date.today()
        company = Transaction().context.get('company')
        balance = Decimal('0.0') 
        transaction = Transaction()
        context = Transaction().context
        total_cash = Decimal('0.0')

        if self.is_consolidated: 
            companies = context.get('companies',[])
            for company in context.get('companies', []):
                with transaction.set_context(company=company['id']):
                    cash = Decimal('0.0')
                    accounts = AccountType.search([('company','=',company['id']),
                        ('name','=','10. Efectivo y Equivalencias de Efectivo')
                        ])
                    if len(accounts)==1: 
                        cash = accounts[0].amount * Decimal('1.0')
                total_cash += cash
            return total_cash
        else: 
            accounts = AccountType.search([('company','=',company),
                ('name','=','10. Efectivo y Equivalencias de Efectivo')])
            if len(accounts)==1: 
                balance = accounts[0].amount * Decimal('1.0')
        return balance
开发者ID:iehoshia,项目名称:training_iesa,代码行数:32,代码来源:account.py

示例3: get_expenses

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [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

示例4: test_user_employee

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [as 别名]
    def test_user_employee(self):
        "Test user employee"
        pool = Pool()
        User = pool.get('res.user')
        transaction = Transaction()

        company = create_company()

        employee1 = create_employee(company, "Jim Halper")
        employee2 = create_employee(company, "Pam Bessly")
        employee3 = create_employee(company, "Michael Scott")

        user1, user2 = User.create([{
                    'name': "Jim Halper",
                    'login': "jim",
                    'main_company': company.id,
                    'company': company.id,
                    'employees': [('add', [employee1.id, employee2.id])],
                    'employee': employee1.id,
                    }, {
                    'name': "Pam Beesly",
                    'login': "pam",
                    'main_company': company.id,
                    'company': company.id,
                    'employees': [('add', [employee2.id])],
                    'employee': employee2.id,
                    }])

        with transaction.set_user(user1.id):
            user1, user2 = User.browse([user1.id, user2.id])
            self.assertEqual(user1.employee, employee1)
            self.assertEqual(user2.employee, employee2)

            with transaction.set_context(employee=employee2.id):
                user1, user2 = User.browse([user1.id, user2.id])
                self.assertEqual(user1.employee, employee2)
                self.assertEqual(user2.employee, employee2)

            with transaction.set_context(employee=None):
                user1, user2 = User.browse([user1.id, user2.id])
                self.assertEqual(user1.employee, None)
                self.assertEqual(user2.employee, employee2)

            with transaction.set_context(employee=employee3.id):
                user1, user2 = User.browse([user1.id, user2.id])
                self.assertEqual(user1.employee, employee1)
                self.assertEqual(user2.employee, employee2)
开发者ID:coopengo,项目名称:company,代码行数:49,代码来源:test_company.py

示例5: get_recommended_capital

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [as 别名]
    def get_recommended_capital(self):
        pool = Pool()
        Date = pool.get('ir.date')
        Fiscalyear = pool.get('account.fiscalyear')
        Budget = pool.get('account.budget')

        today = Date.today()        

        transaction = Transaction()
        context = Transaction().context
        company = context.get('company')
        balance = Decimal('0.0')

        if self.is_consolidated:
            companies = context.get('companies',[])
            for company in context.get('companies', []):
                total_amount = Decimal('0.0')
                with transaction.set_context(company=company['id']):
                    fiscalyears = Fiscalyear.search([('company','=',company['id']),
                        ('start_date','<=',today),
                        ('end_date','>=',today)])
                    fiscalyear = None 
                    if len(fiscalyears)==1: 
                        fiscalyear = fiscalyears[0].id

                    budgets = Budget.search([('fiscalyear','=',fiscalyear),
                        ('company','=',company['id']),
                        ('parent','=',None)])
                    if len(budgets)==1: 
                        budget = Budget(budgets[0].id)
                        balance += budget.children[1].amount * Decimal('0.15') 
            #balance *= -1
        else:
            fiscalyear = Transaction().context.get('fiscalyear')
            if fiscalyear is not None: 
                fiscalyears = Fiscalyear.search([('company','=',company),
                    ('id','=',fiscalyear) ])
            else:
                fiscalyears = Fiscalyear.search([('company','=',company),
                    ('start_date','<=',today),
                    ('end_date','>=',today)])
                if len(fiscalyears)==1: 
                    fiscalyear = fiscalyears[0].id

            budgets = Budget.search([('fiscalyear','=',fiscalyear),
                ('company','=',company),
                ('parent','=',None)])



            if len(budgets)==1: 
                budget = Budget(budgets[0].id)
                print("BUDGET: ", str(budget))
                balance = budget.children[0].amount * Decimal('0.15') 
                print("BALANCE: ", str(balance))
                #balance *= -1

        return balance
开发者ID:iehoshia,项目名称:training_iesa,代码行数:60,代码来源:account.py

示例6: test_user_company

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [as 别名]
    def test_user_company(self):
        'Test user company'
        pool = Pool()
        User = pool.get('res.user')
        transaction = Transaction()

        company1 = create_company()
        company2 = create_company('Michael Scott Paper Company',
            currency=company1.currency)
        company2.parent = company1
        company2.save()
        company3 = create_company()

        user1, user2 = User.create([{
                    'name': 'Jim Halper',
                    'login': 'jim',
                    'main_company': company1.id,
                    'company': company1.id,
                    }, {
                    'name': 'Pam Beesly',
                    'login': 'pam',
                    'main_company': company2.id,
                    'company': company2.id,
                    }])
        self.assertTrue(user1)

        with transaction.set_user(user1.id):
            user1, user2 = User.browse([user1.id, user2.id])
            self.assertEqual(user1.company, company1)
            self.assertEqual(user2.company, company2)

            with transaction.set_context({'company': company2.id}):
                user1, user2 = User.browse([user1.id, user2.id])
                self.assertEqual(user1.company, company2)
                self.assertEqual(user2.company, company2)

            with transaction.set_context({'company': None}):
                user1, user2 = User.browse([user1.id, user2.id])
                self.assertEqual(user1.company, None)
                self.assertEqual(user2.company, company2)

            with transaction.set_context(company=company3.id):
                user1, user2 = User.browse([user1.id, user2.id])
                self.assertEqual(user1.company, company1)
                self.assertEqual(user2.company, company2)
开发者ID:coopengo,项目名称:company,代码行数:47,代码来源:test_company.py

示例7: get_amount_cmp

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [as 别名]
 def get_amount_cmp(cls, types, name):
     transaction = Transaction()
     current = transaction.context
     if not current.get('comparison'):
         return dict.fromkeys([t.id for t in types], None)
     new = {}
     for key, value in current.iteritems():
         if key.endswith('_cmp'):
             new[key[:-4]] = value
     with transaction.set_context(new):
         return cls.get_amount(types, name)
开发者ID:iehoshia,项目名称:training_iesa,代码行数:13,代码来源:account.py

示例8: test_search_cursor_max_histories

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [as 别名]
    def test_search_cursor_max_histories(self):
        'Test search with number of histories at cursor.IN_MAX'
        pool = Pool()
        History = pool.get('test.history')
        transaction = Transaction()
        cursor = transaction.cursor

        n = cursor.IN_MAX + 1
        History.create([{'value': 1}] * n)

        with transaction.set_context(_datetime=datetime.datetime.max):
            records = History.search([])

            self.assertEqual({r.value for r in records}, {1})
            self.assertEqual(len(records), n)
开发者ID:kret0s,项目名称:tryton3_8,代码行数:17,代码来源:test_history.py

示例9: test_search_cursor_max

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [as 别名]
    def test_search_cursor_max(self):
        'Test search with number of history entries at cursor.IN_MAX'
        pool = Pool()
        History = pool.get('test.history')
        transaction = Transaction()
        cursor = transaction.cursor

        history = History(value=-1)
        history.save()

        for history.value in range(cursor.IN_MAX + 1):
            history.save()

        with transaction.set_context(_datetime=datetime.datetime.max):
            record, = History.search([])

            self.assertEqual(record.value, cursor.IN_MAX)
开发者ID:kret0s,项目名称:tryton3_8,代码行数:19,代码来源:test_history.py

示例10: get_amount

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [as 别名]
    def get_amount(cls, types, name):
        pool = Pool()
        Account = pool.get('account.account')
        GeneralLedger = pool.get('account.general_ledger.account')
        transaction = Transaction()
        context = transaction.context

        res = {}
        for type_ in types:
            res[type_.id] = Decimal('0.0')

        childs = cls.search([
                ('parent', 'child_of', [t.id for t in types]),
                ])
        type_sum = {}
        for type_ in childs:
            type_sum[type_.id] = Decimal('0.0')

        start_period_ids = GeneralLedger.get_period_ids('start_%s' % name)
        end_period_ids = GeneralLedger.get_period_ids('end_%s' % name)
        period_ids = list(
            set(end_period_ids).difference(set(start_period_ids)))

        for company in context.get('companies', []):
            with transaction.set_context(company=company['id'],
                    posted=True, cumulate=True):
                accounts = Account.search([
                        ('company', '=', company['id']),
                        ('type.meta_type', 'in', [t.id for t in childs]),
                        ('kind', '!=', 'view'),
                        ])
                for account in accounts:
                    key = account.type.meta_type.id
                    type_sum[key] += (account.debit - account.credit)

        for type_ in types:
            childs = cls.search([
                    ('parent', 'child_of', [type_.id]),
                    ])
            for child in childs:
                res[type_.id] += type_sum[child.id]
            exp = Decimal(str(10.0 ** -type_.currency_digits))
            res[type_.id] = res[type_.id].quantize(exp)
            if type_.display_balance == 'credit-debit':
                res[type_.id] = - res[type_.id]
        return res
开发者ID:iehoshia,项目名称:training_iesa,代码行数:48,代码来源:account.py

示例11: test_search_cursor_max_entries

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [as 别名]
    def test_search_cursor_max_entries(self):
        'Test search for skipping first history entries at cursor.IN_MAX'
        pool = Pool()
        History = pool.get('test.history')
        transaction = Transaction()
        cursor = transaction.cursor

        for i in xrange(0, 2):
            history = History(value=-1)
            history.save()

            for history.value in range(cursor.IN_MAX + 1):
                history.save()

        with transaction.set_context(_datetime=datetime.datetime.max):
            records = History.search([])

            self.assertEqual({r.value for r in records}, {cursor.IN_MAX})
            self.assertEqual(len(records), 2)
开发者ID:kret0s,项目名称:tryton3_8,代码行数:21,代码来源:test_history.py

示例12: transition_create_account

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [as 别名]
    def transition_create_account(self):
        pool = Pool()
        AnalyticAccountTemplate = \
            pool.get('analytic_account.account.template')
        Config = pool.get('ir.configuration')
        Account = pool.get('analytic_account.account')
        
        transaction = Transaction()
        company = self.account.company

        # Skip access rule
        with transaction.set_user(0):
            accounts = Account.search([('company', '=', company.id),
                ('type','=','root'),
                ('parent','=',None),
                ('root','=',None)])

        if len(accounts)>=3:
            self.raise_user_warning('duplicated_chart.%d' % company,
                'account_chart_exists', {
                    'company': company.rec_name,
                    })

        with transaction.set_context(language=Config.get_language(),
                company=company.id):

            # Create analytic plan
            analytic_templates = AnalyticAccountTemplate.search([
                ('type','=','root'),
                ('parent','=',None),
                ('root','=',None)
                ])

            for template in analytic_templates: 
                template2account = {}
                #print ("TEMPLATE: ", str(template))
                template.create_analytic_account(
                    company.id,
                    template2account=template2account, 
                    )
        return 'end'
开发者ID:iehoshia,项目名称:training_iesa,代码行数:43,代码来源:account.py

示例13: transition_create_budget

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [as 别名]
    def transition_create_budget(self):
        pool = Pool()
        BudgetTemplate = \
            pool.get('account.budget.template')
        Budget = pool.get('account.budget')
        Config = pool.get('ir.configuration')
        
        transaction = Transaction()
        company = self.account.company
        fiscalyear = self.account.fiscalyear
        template = self.account.template

        # Skip access rule
        with transaction.set_user(0):
            budgets = Budget.search([
                ('company', '=', company.id),
                ('fiscalyear','=',fiscalyear),
                ('parent','=',None),

            ])

        if budgets:
            #raise BudgetExistForFiscalYear(
            #        gettext('account_budget.msg_budget_already_exist',
            #            fiscalyear=fiscalyear.name,
            #            company=company.rec_name))
            self.raise_user_error('budget_already_exists', {
                        'fiscalyear': fiscalyear.name,
                        'company': company.rec_name,
                        })

        with transaction.set_context(language=Config.get_language(),
                company=company.id):
            template2budget = {}
            template.create_budget(
                company.id,
                fiscalyear.id, 
                template2budget=template2budget, 
                )
        return 'end'
开发者ID:iehoshia,项目名称:training_iesa,代码行数:42,代码来源:budget.py

示例14: transition_create_account

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [as 别名]
    def transition_create_account(self):
        pool = Pool()
        TaxCodeTemplate = pool.get('account.tax.code.template')
        TaxCodeLineTemplate = pool.get('account.tax.code.line.template')
        TaxTemplate = pool.get('account.tax.template')
        TaxRuleTemplate = pool.get('account.tax.rule.template')
        TaxRuleLineTemplate = \
            pool.get('account.tax.rule.line.template')
        Config = pool.get('ir.configuration')
        Account = pool.get('account.account')
        transaction = Transaction()

        company = self.account.company
        # Skip access rule
        with transaction.set_user(0):
            accounts = Account.search([('company', '=', company.id)], limit=1)
        if accounts:
            self.raise_user_warning('duplicated_chart.%d' % company.id,
                'account_chart_exists', {
                    'company': company.rec_name,
                    })

        with transaction.set_context(language=Config.get_language(),
                company=company.id):
            account_template = self.account.account_template
            account_meta_template = self.account.meta_type

            # Get account meta types
            template2meta_type = {}
            account_meta_template.update_type(template2type=template2meta_type)

            # Create account types
            template2type = {}
            account_template.type.create_type(
                company.id,
                template2type=template2type,
                template2meta_type=template2meta_type)

            # Create accounts
            template2account = {}
            account_template.create_account(
                company.id,
                template2account=template2account,
                template2type=template2type)

            # Create taxes
            template2tax = {}
            TaxTemplate.create_tax(
                account_template.id, company.id,
                template2account=template2account,
                template2tax=template2tax)

            # Create tax codes
            template2tax_code = {}
            TaxCodeTemplate.create_tax_code(
                account_template.id, company.id,
                template2tax_code=template2tax_code)

            # Create tax code lines
            template2tax_code_line = {}
            TaxCodeLineTemplate.create_tax_code_line(
                account_template.id,
                template2tax=template2tax,
                template2tax_code=template2tax_code,
                template2tax_code_line=template2tax_code_line)

            # Update taxes and replaced_by on accounts
            account_template.update_account2(template2account, template2tax)

            # Create tax rules
            template2rule = {}
            TaxRuleTemplate.create_rule(
                account_template.id, company.id,
                template2rule=template2rule)

            # Create tax rule lines
            template2rule_line = {}
            TaxRuleLineTemplate.create_rule_line(
                account_template.id, template2tax, template2rule,
                template2rule_line=template2rule_line)
        return 'properties'
开发者ID:iehoshia,项目名称:training_iesa,代码行数:83,代码来源:template.py

示例15: test_account_debit_credit

# 需要导入模块: from trytond.transaction import Transaction [as 别名]
# 或者: from trytond.transaction.Transaction import set_context [as 别名]

#.........这里部分代码省略.........
            analytic_account, = AnalyticAccount.create([{
                        'type': 'normal',
                        'name': 'Analytic Account',
                        'parent': root.id,
                        'root': root.id,
                        }])
            create_chart(company)
            fiscalyear = get_fiscalyear(company)
            fiscalyear.save()
            fiscalyear.create_period([fiscalyear])
            period = fiscalyear.periods[0]
            journal_revenue, = Journal.search([
                    ('code', '=', 'REV'),
                    ])
            journal_expense, = Journal.search([
                    ('code', '=', 'EXP'),
                    ])
            revenue, = Account.search([
                    ('kind', '=', 'revenue'),
                    ])
            receivable, = Account.search([
                    ('kind', '=', 'receivable'),
                    ])
            expense, = Account.search([
                    ('kind', '=', 'expense'),
                    ])
            payable, = Account.search([
                    ('kind', '=', 'payable'),
                    ])

            first_account_line = {
                'account': revenue.id,
                'credit': Decimal(100),
                'analytic_lines': [
                    ('create', [{
                                'account': analytic_account.id,
                                'name': 'Analytic Line',
                                'credit': Decimal(100),
                                'debit': Decimal(0),
                                'journal': journal_revenue.id,
                                'date': period.start_date,
                                }])
                    ]}
            second_account_line = {
                'account': expense.id,
                'debit': Decimal(30),
                'analytic_lines': [
                    ('create', [{
                                'account': analytic_account.id,
                                'name': 'Analytic Line',
                                'debit': Decimal(30),
                                'credit': Decimal(0),
                                'journal': journal_expense.id,
                                'date': period.start_date,
                                }])
                    ]}
            # Create some moves
            vlist = [{
                    'period': period.id,
                    'journal': journal_revenue.id,
                    'date': period.start_date,
                    'lines': [
                        ('create', [first_account_line, {
                                    'account': receivable.id,
                                    'debit': Decimal(100),
                                    'party': party.id,
                                    }]),
                        ],
                    }, {
                    'period': period.id,
                    'journal': journal_expense.id,
                    'date': period.start_date,
                    'lines': [
                        ('create', [second_account_line, {
                                    'account': payable.id,
                                    'credit': Decimal(30),
                                    'party': party.id,
                                    }]),
                        ],
                    },
                ]
            Move.create(vlist)

            self.assertEqual((analytic_account.debit, analytic_account.credit),
                (Decimal(30), Decimal(100)))
            self.assertEqual(analytic_account.balance, Decimal(70))

            with transaction.set_context(start_date=period.end_date):
                analytic_account = AnalyticAccount(analytic_account.id)
                self.assertEqual((analytic_account.debit,
                        analytic_account.credit),
                    (Decimal(0), Decimal(0)))
                self.assertEqual(analytic_account.balance, Decimal(0))

            with transaction.set_context(end_date=period.end_date):
                analytic_account = AnalyticAccount(analytic_account.id)
                self.assertEqual((analytic_account.debit,
                        analytic_account.credit),
                    (Decimal(30), Decimal(100)))
                self.assertEqual(analytic_account.balance, Decimal(70))
开发者ID:kret0s,项目名称:tryton3_8,代码行数:104,代码来源:test_analytic_account.py


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