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


Python Pool.compute方法代码示例

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


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

示例1: _compute_taxes

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
    def _compute_taxes(self):
        Tax = Pool().get('account.tax')

        context = self.get_tax_context()

        res = {}
        for line in self.lines:
            # Don't round on each line to handle rounding error
            if line.type != 'line':
                continue
            with Transaction().set_context(**context):
                if(line.product and line.product.dont_multiply):
                    taxes = Tax.compute(line.taxes, line.unit_price,
                        1.0)
                else:
                    taxes = Tax.compute(line.taxes, line.unit_price,
                        line.quantity)
            for tax in taxes:
                key, val = self._compute_tax(tax, self.type)
                val['invoice'] = self.id
                if not key in res:
                    res[key] = val
                else:
                    res[key]['base'] += val['base']
                    res[key]['amount'] += val['amount']
        for key in res:
            for field in ('base', 'amount'):
                res[key][field] = self.currency.round(res[key][field])
        return res
开发者ID:ferchuochoa,项目名称:SIGCoop,代码行数:31,代码来源:invoice.py

示例2: _get_move_line

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
 def _get_move_line(self, date, amount, account_id, party_required=False):
     '''
     Return move line
     '''
     Currency = Pool().get('currency.currency')
     res = {}
     if self.currency.id != self.company.currency.id:
         with Transaction().set_context(date=self.date):
             res['amount_second_currency'] = Currency.compute(
                 self.company.currency, amount, self.currency)
         res['amount_second_currency'] = abs(res['amount_second_currency'])
         res['second_currency'] = self.currency.id
     else:
         res['amount_second_currency'] = Decimal('0.0')
         res['second_currency'] = None
     if amount >= Decimal('0.0'):
         res['debit'] = Decimal('0.0')
         res['credit'] = amount
     else:
         res['debit'] = - amount
         res['credit'] = Decimal('0.0')
     res['account'] = account_id
     res['maturity_date'] = date
     res['description'] = self.description
     if party_required:
         res['party'] = self.party.id
     return res
开发者ID:gcoop-libre,项目名称:cooperative_ar,代码行数:29,代码来源:recibo.py

示例3: create_move

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
    def create_move(self, date=None):
        """
        Create the account move for the payment

        :param date: Optional date for the account move
        :return: Active record of the created move
        """
        Currency = Pool().get('currency.currency')
        Period = Pool().get('account.period')
        Move = Pool().get('account.move')

        journal = self.gateway.journal
        date = date or self.date

        if not journal.debit_account:
            self.raise_user_error('missing_debit_account', (journal.rec_name,))

        period_id = Period.find(self.company.id, date=date)

        amount_second_currency = second_currency = None
        amount = self.amount

        if self.currency != self.company.currency:
            amount = Currency.compute(
                self.currency, self.amount, self.company.currency
            )
            amount_second_currency = self.amount
            second_currency = self.currency

        lines = [{
            'description': self.rec_name,
            'account': self.credit_account.id,
            'party': self.party.id,
            'debit': Decimal('0.0'),
            'credit': amount,
            'amount_second_currency': amount_second_currency,
            'second_currency': second_currency,
        }, {
            'description': self.rec_name,
            'account': journal.debit_account.id,
            'debit': amount,
            'credit': Decimal('0.0'),
            'amount_second_currency': amount_second_currency,
            'second_currency': second_currency,
        }]

        move, = Move.create([{
            'journal': journal.id,
            'period': period_id,
            'date': date,
            'lines': [('create', lines)],
            'origin': '%s,%d' % (self.__name__, self.id),
        }])
        Move.post([move])

        # Set the move as the move of this transaction
        self.move = move
        self.save()

        return move
开发者ID:priyankarani,项目名称:trytond-payment-gateway,代码行数:62,代码来源:transaction.py

示例4: get_move_line

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
    def get_move_line(self):
        '''
        Return the move line for the statement line
        '''
        pool = Pool()
        MoveLine = pool.get('account.move.line')
        Currency = Pool().get('currency.currency')
        zero = Decimal("0.0")
        with Transaction().set_context(date=self.date):
            amount = Currency.compute(self.statement.journal.currency,
                self.amount, self.statement.company.currency)
        if self.statement.journal.currency != self.statement.company.currency:
            second_currency = self.statement.journal.currency.id
            amount_second_currency = -self.amount
        else:
            amount_second_currency = None
            second_currency = None

        return MoveLine(
            description=self.description,
            debit=amount < zero and -amount or zero,
            credit=amount >= zero and amount or zero,
            account=self.account,
            party=self.party if self.account.party_required else None,
            second_currency=second_currency,
            amount_second_currency=amount_second_currency,
            )
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:29,代码来源:statement.py

示例5: on_change_amount

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
    def on_change_amount(self):
        Currency = Pool().get('currency.currency')
        res = {}

        if self.party:
            if self.account and self.account not in (
                    self.party.account_receivable, self.party.account_payable):
                # The user has entered a non-default value, we keep it.
                pass
            elif self.amount:
                if self.amount > Decimal("0.0"):
                    account = self.party.account_receivable
                else:
                    account = self.party.account_payable
                res['account'] = account.id
                res['account.rec_name'] = account.rec_name
        if self.invoice:
            if self.amount and self.statement and self.statement.journal:
                invoice = self.invoice
                journal = self.statement.journal
                with Transaction().set_context(date=invoice.currency_date):
                    amount_to_pay = Currency.compute(invoice.currency,
                        invoice.amount_to_pay, journal.currency)
                if abs(self.amount) > amount_to_pay:
                    res['invoice'] = None
            else:
                res['invoice'] = None
        return res
开发者ID:aleibrecht,项目名称:tryton-modules-ar,代码行数:30,代码来源:statement.py

示例6: update_pricelist_shipment_cost

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
    def update_pricelist_shipment_cost(self):
        "Add a shipping line to sale for pricelist costmethod"
        Sale = Pool().get('sale.sale')
        Currency = Pool().get('currency.currency')

        if not self.carrier or self.carrier.carrier_cost_method != 'pricelist':
            return

        with Transaction().set_context(self._get_carrier_context()):
            shipment_cost = self.carrier.get_sale_price()
        if not shipment_cost[0]:
            return

        shipment_cost = Currency.compute(
            Currency(shipment_cost[1]), shipment_cost[0], self.currency
        )
        Sale.write([self], {
            'lines': [
                ('create', [{
                    'type': 'line',
                    'product': self.carrier.carrier_product.id,
                    'description': self.carrier.carrier_product.name,
                    'quantity': 1,  # XXX
                    'unit': self.carrier.carrier_product.sale_uom.id,
                    'unit_price': Decimal(shipment_cost),
                    'shipment_cost': Decimal(shipment_cost),
                    'amount': Decimal(shipment_cost),
                    'taxes': [],
                    'sequence': 9999,  # XXX
                }]),
                ('delete', [
                    line for line in self.lines if line.shipment_cost
                ]),
            ]
        })
开发者ID:fulfilio,项目名称:trytond-carrier-pricelist,代码行数:37,代码来源:sale.py

示例7: apply_ups_shipping

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
    def apply_ups_shipping(self):
        "Add a shipping line to sale for ups"
        Sale = Pool().get('sale.sale')
        Currency = Pool().get('currency.currency')

        if self.is_ups_shipping:
            with Transaction().set_context(self._get_carrier_context()):
                shipment_cost, currency_id = self.carrier.get_sale_price()
                if not shipment_cost:
                    return
            # Convert the shipping cost to sale currency from USD
            shipment_cost = Currency.compute(
                Currency(currency_id), shipment_cost, self.currency
            )
            Sale.write([self], {
                'lines': [
                    ('create', [{
                        'type': 'line',
                        'product': self.carrier.carrier_product.id,
                        'description': self.ups_service_type.name,
                        'quantity': 1,  # XXX
                        'unit': self.carrier.carrier_product.sale_uom.id,
                        'unit_price': shipment_cost,
                        'shipment_cost': shipment_cost,
                        'amount': shipment_cost,
                        'taxes': [],
                        'sequence': 9999,  # XXX
                    }]),
                    ('delete', [
                        line for line in self.lines if line.shipment_cost
                    ]),
                ]
            })
开发者ID:mbehrle,项目名称:trytond-shipping-ups,代码行数:35,代码来源:sale.py

示例8: apply_shipping_rate

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
    def apply_shipping_rate(self, rate):
        """
        This method applies shipping rate. Rate is a dictionary with
        following minimum keys:

            {
                'display_name': Name to display,
                'carrier_service': carrier.service active record,
                'cost': cost,
                'cost_currency': currency.currency active repord,
                'carrier': carrier active record,
            }
        """
        Currency = Pool().get('currency.currency')

        shipment_cost = rate['cost_currency'].round(rate['cost'])
        if self.cost_currency != rate['cost_currency']:
            shipment_cost = Currency.compute(
                rate['cost_currency'], shipment_cost, self.cost_currency
            )

        self.cost = shipment_cost
        self.cost_currency = self.cost_currency
        self.carrier = rate['carrier']
        self.carrier_service = rate['carrier_service']
        self.save()
开发者ID:fulfilio,项目名称:trytond-shipping,代码行数:28,代码来源:mixin.py

示例9: get_value

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
 def get_value(self, remainder, amount, currency):
     Currency = Pool().get("currency.currency")
     if self.type == "fixed":
         return Currency.compute(self.currency, self.amount, currency)
     elif self.type == "percent":
         return currency.round(remainder * self.percentage / Decimal("100"))
     elif self.type == "percent_on_total":
         return currency.round(amount * self.percentage / Decimal("100"))
     elif self.type == "remainder":
         return currency.round(remainder)
     return None
开发者ID:silpol,项目名称:tryton-bef,代码行数:13,代码来源:payment_term.py

示例10: get_value

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
 def get_value(self, remainder, amount, currency):
     Currency = Pool().get('currency.currency')
     if self.type == 'fixed':
         return Currency.compute(self.currency, self.amount, currency)
     elif self.type == 'percent':
         return currency.round(remainder * self.ratio)
     elif self.type == 'percent_on_total':
         return currency.round(amount * self.ratio)
     elif self.type == 'remainder':
         return currency.round(remainder)
     return None
开发者ID:kret0s,项目名称:tryton3_8,代码行数:13,代码来源:payment_term.py

示例11: apply_ups_shipping

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
    def apply_ups_shipping(self):
        "Add a shipping line to sale for ups"
        Currency = Pool().get("currency.currency")

        if self.is_ups_shipping:
            with Transaction().set_context(self._get_carrier_context()):
                shipment_cost, currency_id = self.carrier.get_sale_price()
                if not shipment_cost:
                    return
            # Convert the shipping cost to sale currency from USD
            shipment_cost = Currency.compute(Currency(currency_id), shipment_cost, self.currency)
            self.add_shipping_line(shipment_cost, "%s - %s" % (self.carrier.party.name, self.ups_service_type.name))
开发者ID:tarunbhardwaj,项目名称:trytond-shipping-ups,代码行数:14,代码来源:sale.py

示例12: create_using_amazon_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
    def create_using_amazon_data(cls, product_data):
        """
        Create a new product with the `product_data` from amazon.

        :param product_data: Product Data from Amazon
        :returns: Active record of product created
        """
        Template = Pool().get('product.template')
        Currency = Pool().get('currency.currency')
        SaleChannel = Pool().get('sale.channel')

        # TODO: Handle attribute sets in multiple languages
        product_attribute_set = product_data['Products']['Product'][
            'AttributeSets'
        ]
        if isinstance(product_attribute_set, dict):
            product_attributes = product_attribute_set['ItemAttributes']
        else:
            product_attributes = product_attribute_set[0]['ItemAttributes']

        product_values = cls.extract_product_values_from_amazon_data(
            product_attributes
        )

        amazon_channel = SaleChannel(
            Transaction().context['current_channel']
        )
        assert amazon_channel.source == 'amazon_mws'

        list_price = Decimal('0.01')
        if product_attributes.get('ListPrice'):
            list_price = product_attributes['ListPrice']['Amount']['value']
            currency_code = product_attributes['ListPrice']['CurrencyCode']['value']  # noqa
            currency, = Currency.search([
                ('code', '=', currency_code),
            ], limit=1)
            list_price = Currency.compute(
                currency, Decimal(list_price),
                amazon_channel.company.currency
            )

        product_values.update({
            'products': [('create', [{
                'code': product_data['Id']['value'],
                'list_price': list_price,
                'cost_price': list_price,
                'description': product_attributes['Title']['value'],
            }])],
        })

        product_template, = Template.create([product_values])

        return product_template.products[0]
开发者ID:Jason-Kou,项目名称:trytond-amazon-mws,代码行数:55,代码来源:product.py

示例13: _get_move_lines

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
    def _get_move_lines(self):
        '''
        Return the move lines for the statement line
        '''
        pool = Pool()
        MoveLine = pool.get('account.move.line')
        Currency = Pool().get('currency.currency')
        zero = Decimal("0.0")
        with Transaction().set_context(date=self.date):
            amount = Currency.compute(self.statement.journal.currency,
                self.amount, self.statement.company.currency)
        if self.statement.journal.currency != self.statement.company.currency:
            second_currency = self.statement.journal.currency.id
            amount_second_currency = abs(self.amount)
        else:
            amount_second_currency = None
            second_currency = None

        move_lines = []
        move_lines.append(MoveLine(
                description=self.description,
                debit=amount < zero and -amount or zero,
                credit=amount >= zero and amount or zero,
                account=self.account,
                party=self.party if self.account.party_required else None,
                second_currency=second_currency,
                amount_second_currency=amount_second_currency,
                ))

        journal = self.statement.journal.journal
        if self.amount >= zero:
            account = journal.debit_account
        else:
            account = journal.credit_account
        if not account:
            self.raise_user_error('debit_credit_account_statement_journal',
                (journal.rec_name,))
        if self.account == account:
            self.raise_user_error('same_debit_credit_account', {
                    'account': self.account.rec_name,
                    'line': self.rec_name,
                    'journal': journal,
                    })
        move_lines.append(MoveLine(
                description=self.description,
                debit=amount >= zero and amount or zero,
                credit=amount < zero and -amount or zero,
                account=account,
                party=self.party if account.party_required else None,
                second_currency=second_currency,
                amount_second_currency=amount_second_currency,
                ))
        return move_lines
开发者ID:aleibrecht,项目名称:tryton-modules-ar,代码行数:55,代码来源:statement.py

示例14: get_other_taxes

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
 def get_other_taxes(cls, invoice):
     Currency = Pool().get('currency.currency')
     amount = Decimal('0')
     for invoice_tax in invoice.taxes:
         if (invoice_tax.tax.group and invoice_tax.tax.group.code.lower()
                 not in ['iibb', 'iva']):
             tax_amount = invoice_tax.amount
             if invoice.currency.id != invoice.company.currency.id:
                 amount += Currency.compute(
                     invoice.currency, tax_amount, invoice.company.currency)
             else:
                 amount += invoice.currency.round(tax_amount)
     return amount
开发者ID:tryton-ar,项目名称:subdiario,代码行数:15,代码来源:subdiario.py

示例15: apply_product_shipping

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute [as 别名]
    def apply_product_shipping(self):
        """
        This method apply product(carrier) shipping.
        """
        Currency = Pool().get('currency.currency')

        with Transaction().set_context(self._get_carrier_context()):
            shipment_cost, currency_id = self.carrier.get_sale_price()

        shipment_cost = Currency.compute(
            Currency(currency_id), shipment_cost, self.currency
        )
        self.add_shipping_line(shipment_cost, self.carrier.rec_name)
开发者ID:bhavana94,项目名称:trytond-shipping,代码行数:15,代码来源:sale.py


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