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


Python Pool.open_cart方法代码示例

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


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

示例1: _user_status

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def _user_status(cls):
        """Add cart size and amount to the dictionary
        """
        Cart = Pool().get('nereid.cart')
        cart = Cart.open_cart()

        rv = super(Website, cls)._user_status()

        if cart.sale:
            # Build locale based formatters
            currency_format = partial(
                numbers.format_currency, currency=cart.sale.currency.code,
                locale=current_locale.language.code
            )

            rv['cart'] = {
                'lines': [
                    line.serialize(purpose='cart')
                    for line in cart.sale.lines
                ],
                'empty': len(cart.sale.lines) > 0,
                'total_amount': currency_format(cart.sale.total_amount),
                'tax_amount': currency_format(cart.sale.tax_amount),
                'untaxed_amount': currency_format(cart.sale.untaxed_amount),
            }
            rv['cart_total_amount'] = currency_format(
                cart.sale and cart.sale.total_amount or 0
            )

        rv['cart_size'] = '%s' % Cart.cart_size()

        return rv
开发者ID:fulfilio,项目名称:nereid-cart-b2c,代码行数:34,代码来源:website.py

示例2: _submit_guest

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def _submit_guest(cls):
        '''Submission when guest user'''
        Cart = Pool().get('nereid.cart')
        Sale = Pool().get('sale.sale')

        form = OneStepCheckout(request.form)
        cart = Cart.open_cart()
        if form.validate():
            # Get billing address
            billing_address = cls._create_address(
                form.new_billing_address.data
            )

            # Get shipping address
            shipping_address = billing_address
            if not form.shipping_same_as_billing:
                shipping_address = cls._create_address(
                    form.new_shipping_address.data
                )

            # Write the information to the order
            Sale.write(
                [cart.sale], {
                    'invoice_address': billing_address,
                    'shipment_address': shipping_address,
                }
            )
        return form, form.validate()
开发者ID:pokoli,项目名称:nereid-checkout,代码行数:30,代码来源:checkout.py

示例3: _submit_registered

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def _submit_registered(self):
        """Submission when registered user"""
        cart_obj = Pool().get("nereid.cart")
        sale_obj = Pool().get("sale.sale")
        from trytond.modules.nereid_checkout.forms import OneStepCheckoutRegd

        form = OneStepCheckoutRegd(request.form)
        addresses = cart_obj._get_addresses()
        form.billing_address.choices.extend(addresses)
        form.shipping_address.choices.extend(addresses)
        form.payment_method.choices = [(m.id, m.name) for m in request.nereid_website.allowed_gateways]
        form.shipment_method.validators = []

        cart = cart_obj.open_cart()
        if form.validate():
            # Get billing address
            if form.billing_address.data == 0:
                # New address
                billing_address = self._create_address(form.new_billing_address.data)
            else:
                billing_address = form.billing_address.data

            # Get shipping address
            shipping_address = billing_address
            if not form.shipping_same_as_billing:
                if form.shipping_address.data == 0:
                    shipping_address = self._create_address(form.new_shipping_address.data)
                else:
                    shipping_address = form.shipping_address.data

            # Write the information to the order
            sale_obj.write(cart.sale.id, {"invoice_address": billing_address, "shipment_address": shipping_address})

        return form, form.validate()
开发者ID:openlabs,项目名称:nereid-demo-store,代码行数:36,代码来源:checkout.py

示例4: checkout

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def checkout(self):
        '''Submit of default checkout

        A GET to the method will result in passing of control to begin as
        that is basically the entry point to the checkout

        A POST to the method will result in the confirmation of the order and
        subsequent handling of data.
        '''
        cart_obj = Pool().get('nereid.cart')
        sale_obj = Pool().get('sale.sale')

        cart = cart_obj.open_cart()
        if not cart.sale:
            # This case is possible if the user changes his currency at
            # the point of checkout and the cart gets cleared.
            return redirect(url_for('nereid.cart.view_cart'))

        sale = cart.sale
        if not sale.lines:
            flash(_("Add some items to your cart before you checkout!"))
            return redirect(url_for('nereid.website.home'))
        if request.method == 'GET':
            return (self._begin_guest() if request.is_guest_user \
                else self._begin_registered())

        elif request.method == 'POST':
            form, do_process = self._submit_guest() if request.is_guest_user \
                else self._submit_registered()
            if do_process:
                # Process Shipping
                self._process_shipment(sale, form)

                # Process Payment, if the returned value from the payment
                # is a response object (isinstance) then return that instead
                # of the success page. This will allow reidrects to a third 
                # party gateway or service to collect payment.
                response = self._process_payment(sale, form)
                if isinstance(response, BaseResponse):
                    return response

                if sale.state == 'draft':
                    # Ensure that the order date is that of today
                    cart_obj.check_update_date(cart)
                    # Confirm the order
                    sale_obj.quote([sale.id])
                    sale_obj.confirm([sale.id])

                flash(_("Your order #%(sale)s has been processed", sale=sale.reference))
                if request.is_guest_user:
                    return redirect(url_for('nereid.website.home'))
                else:
                    return redirect(
                        url_for(
                            'sale.sale.render', sale=sale.id, 
                            confirmation=True
                        )
                    )

            return render_template('checkout.jinja', form=form, cart=cart)
开发者ID:shalabhaggarwal,项目名称:nereid-checkout,代码行数:62,代码来源:checkout.py

示例5: get_payment_form

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def get_payment_form(cls):
        '''
        Return a payment form
        '''
        NereidCart = Pool().get('nereid.cart')

        cart = NereidCart.open_cart()

        payment_form = PaymentForm()

        # add possible alternate payment_methods
        payment_form.alternate_payment_method.choices = [
            (m.id, m.name) for m in cart.get_alternate_payment_methods()
        ]

        # add profiles of the registered user
        if not current_user.is_anonymous():
            payment_form.payment_profile.choices = [
                (p.id, p.rec_name) for p in
                current_user.party.get_payment_profiles()
            ]

        if (cart.sale.shipment_address == cart.sale.invoice_address) or (
                not cart.sale.invoice_address):
            payment_form.use_shipment_address.data = "y"

        return payment_form
开发者ID:priyankarani,项目名称:nereid-checkout,代码行数:29,代码来源:checkout.py

示例6: wrapper

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
 def wrapper(*args, **kwargs):
     NereidCart = Pool().get('nereid.cart')
     cart = NereidCart.open_cart()
     if not (cart.sale and cart.sale.lines):
         current_app.logger.debug(
             'No sale or lines. Redirect to shopping-cart'
         )
         return redirect(url_for('nereid.cart.view_cart'))
     return function(*args, **kwargs)
开发者ID:priyankarani,项目名称:nereid-checkout,代码行数:11,代码来源:checkout.py

示例7: _begin_guest

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def _begin_guest(cls):
        """Start of checkout process for guest user which is different
        from login user who may already have addresses
        """
        Cart = Pool().get('nereid.cart')

        cart = Cart.open_cart()
        form = OneStepCheckout(request.form)

        return render_template('checkout.jinja', form=form, cart=cart)
开发者ID:pokoli,项目名称:nereid-checkout,代码行数:12,代码来源:checkout.py

示例8: _begin_registered

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def _begin_registered(cls):
        '''Begin checkout process for registered user.'''
        Cart = Pool().get('nereid.cart')

        cart = Cart.open_cart()
        form = OneStepCheckoutRegd(request.form)
        addresses = [(0, _('New Address'))] + Cart._get_addresses()
        form.billing_address.choices = addresses
        form.shipping_address.choices = addresses

        return render_template('checkout.jinja', form=form, cart=cart)
开发者ID:pokoli,项目名称:nereid-checkout,代码行数:13,代码来源:checkout.py

示例9: login_event_handler

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
def login_event_handler(website_obj=None):
    """This method is triggered when a login event occurs.

    When a user logs in, all items in his guest cart should be added to his
    logged in or registered cart. If there is no such cart, it should be
    created.

    .. versionchanged:: 2.4.0.1
        website_obj was previously a mandatory argument because the pool
        object in the class was required to load other objects from the pool.
        Since pool object is a singleton, this object is not required.
    """

    if website_obj is not None:
        warnings.warn(
            "login_event_handler will not accept arguments from "
            "Version 2.5 +", DeprecationWarning, stacklevel=2
        )

    try:
        Cart = Pool().get('nereid.cart')
    except KeyError:
        # Just return silently. This KeyError is cause if the module is not
        # installed for a specific database but exists in the python path
        # and is loaded by the tryton module loader
        current_app.logger.warning(
            "nereid-cart-b2c module installed but not in database"
        )
        return

    # Find the guest cart
    try:
        guest_cart, = Cart.search([
            ('sessionid', '=', session.sid),
            ('user', '=', request.nereid_website.guest_user.id),
            ('website', '=', request.nereid_website.id)
        ], limit=1)
    except ValueError:
        return

    # There is a cart
    if guest_cart.sale and guest_cart.sale.lines:
        to_cart = Cart.open_cart(True)
        # Transfer lines from one cart to another
        for from_line in guest_cart.sale.lines:
            Cart._add_or_update(
                to_cart.sale.id, from_line.product.id, from_line.quantity
            )

    # Clear and delete the old cart
    guest_cart._clear_cart()
开发者ID:rahulsukla,项目名称:nereid-cart-b2c,代码行数:53,代码来源:cart.py

示例10: _begin_registered

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def _begin_registered(self):
        """Begin checkout process for registered user."""
        cart_obj = Pool().get("nereid.cart")
        from trytond.modules.nereid_checkout.forms import OneStepCheckoutRegd

        cart = cart_obj.open_cart()

        form = OneStepCheckoutRegd(request.form)
        addresses = [(0, _("New Address"))] + cart_obj._get_addresses()
        form.billing_address.choices = addresses
        form.shipping_address.choices = addresses
        form.payment_method.choices = [(m.id, m.name) for m in request.nereid_website.allowed_gateways]

        return render_template("checkout.jinja", form=form, cart=cart)
开发者ID:openlabs,项目名称:nereid-demo-store,代码行数:16,代码来源:checkout.py

示例11: _process_payment

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def _process_payment(cls, cart):
        """
        This is separated so that other modules can easily modify the
        behavior of processing payment independent of this module.
        """
        NereidCart = Pool().get('nereid.cart')
        PaymentProfile = Pool().get('party.payment_profile')
        PaymentMethod = Pool().get('nereid.website.payment_method')

        cart = NereidCart.open_cart()
        payment_form = cls.get_payment_form()
        credit_card_form = cls.get_credit_card_form()

        if not current_user.is_anonymous() and \
                payment_form.payment_profile.data:
            # Regd. user with payment_profile
            rv = cart.sale._add_sale_payment(
                payment_profile=PaymentProfile(
                    payment_form.payment_profile.data
                )
            )
            if isinstance(rv, BaseResponse):
                # Redirects only if payment profile is invalid.
                # Then do not confirm the order, just redirect
                return rv
            return cls.confirm_cart(cart)

        elif payment_form.alternate_payment_method.data:
            # Checkout using alternate payment method
            rv = cart.sale._add_sale_payment(
                alternate_payment_method=PaymentMethod(
                    payment_form.alternate_payment_method.data
                )
            )
            if isinstance(rv, BaseResponse):
                # If the alternate payment method introduced a
                # redirect, then save the order and go to that
                cls.confirm_cart(cart)
                return rv
            return cls.confirm_cart(cart)

        elif request.nereid_website.credit_card_gateway and \
                credit_card_form.validate():
            # validate the credit card form and checkout using that
            cart.sale._add_sale_payment(
                credit_card_form=credit_card_form
            )
            return cls.confirm_cart(cart)
开发者ID:priyankarani,项目名称:nereid-checkout,代码行数:50,代码来源:checkout.py

示例12: payment_method

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def payment_method(cls):
        '''
        Select/Create a payment method

        Allows adding new payment profiles for registered users. Guest users
        are allowed to fill in credit card information or chose from one of
        the existing payment gateways.
        '''
        NereidCart = Pool().get('nereid.cart')
        PaymentMethod = Pool().get('nereid.website.payment_method')
        Date = Pool().get('ir.date')

        cart = NereidCart.open_cart()
        if not cart.sale.shipment_address:
            return redirect(url_for('nereid.checkout.shipping_address'))

        payment_form = cls.get_payment_form()
        credit_card_form = cls.get_credit_card_form()

        if request.method == 'POST' and payment_form.validate():

            # Setting sale date as current date
            cart.sale.sale_date = Date.today()
            cart.sale.save()

            # call the billing address method which will handle any
            # address submission that may be there in this request
            cls.billing_address()

            if not cart.sale.invoice_address:
                # If still there is no billing address. Do not proceed
                # with this
                return redirect(url_for('nereid.checkout.billing_address'))

            rv = cls._process_payment(cart)
            if isinstance(rv, BaseResponse):
                # Return if BaseResponse
                return rv

            flash(_("Error is processing payment."), "warning")

        return render_template(
            'checkout/payment_method.jinja',
            payment_form=payment_form,
            credit_card_form=credit_card_form,
            PaymentMethod=PaymentMethod,
        )
开发者ID:priyankarani,项目名称:nereid-checkout,代码行数:49,代码来源:checkout.py

示例13: validate_address

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def validate_address(cls):
        '''
        Validation of shipping address (optional)

        Shipping address can be validated and address suggestions could be shown
        to the user. Here user can chooose address from suggestion and update
        the saved address on `POST`
        '''
        NereidCart = Pool().get('nereid.cart')

        cart = NereidCart.open_cart()

        if not cart.sale.shipment_address:
            return redirect(url_for('nereid.checkout.shipping_address'))

        # TODO: Not implemented yet
        return redirect(url_for('nereid.checkout.delivery_method'))
开发者ID:priyankarani,项目名称:nereid-checkout,代码行数:19,代码来源:checkout.py

示例14: set_currency

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def set_currency(cls):
        """Sets the currency for current session. A change in the currency
        should reset the cart if the currency of the cart is not the same as
        the one here
        """
        Cart = Pool().get('nereid.cart')

        rv = super(Website, cls).set_currency()

        # TODO: If currency has changed drop the cart
        # This behaviour needs serious improvement. Probably create a new cart
        # with all items in this cart and then drop this one
        cart = Cart.open_cart()
        if cart.sale and cart.sale.currency.id != session['currency']:
            Cart.clear_cart()

        return rv
开发者ID:fulfilio,项目名称:nereid-cart-b2c,代码行数:19,代码来源:website.py

示例15: delivery_method

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import open_cart [as 别名]
    def delivery_method(cls):
        '''
        Selection of delivery method (options)

        Based on the shipping address selected, the delivery options
        could be shown to the user. This may include choosing shipping speed
        and if there are multiple items, the option to choose items as they are
        available or all at once.
        '''
        NereidCart = Pool().get('nereid.cart')

        cart = NereidCart.open_cart()

        if not cart.sale.shipment_address:
            return redirect(url_for('nereid.checkout.shipping_address'))

        # TODO: Not implemented yet
        return redirect(url_for('nereid.checkout.payment_method'))
开发者ID:priyankarani,项目名称:nereid-checkout,代码行数:20,代码来源:checkout.py


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