Skip to main content
Odoo Community Association

Shopinvader API Cart Options

Beta License: AGPL-3 shopinvader/odoo-shopinvader

This module allows to add options to the cart lines, grouping cart transaction on the combination of the product and the options.

It also handles the cart transfer merge by using the options to merge the cart lines.

Table of contents

Usage

This module is designed to be extended, so you can add your own options to the cart lines.

In order to do so, you need to extend the SaleLineOptions schema and add your own options:

class SaleLineOptions(BaseSaleLineOptions, extends=True):
    engraving: str | None = None
    special: bool = False

    @classmethod
    def from_sale_order_line(cls, odoo_rec):
        rv = super().from_sale_order_line(odoo_rec)
        rv.engraving = odoo_rec.carving or None
        rv.special = odoo_rec.special
        return rv

Then you will need to extend the SaleOrderLine model to add support for you options in the cart line matching and in the cart line transfer:

class SaleOrderLine(models.Model):
    _inherit = "sale.order.line"
    carving = fields.Char()
    special = fields.Boolean()

    def _match_cart_line(
        self,
        product_id,
        carving=None,
        special=None,
        **kwargs,
    ):
        rv = super()._match_cart_line(
            product_id,
            carving=carving,
            special=special,
            **kwargs,
        )
        return rv and self.carving == carving and self.special == special

    def _prepare_cart_line_transfer_values(self):
        vals = super()._prepare_cart_line_transfer_values()
        vals["carving"] = self.carving
        vals["special"] = self.special
        return vals

And finally, you will need to extend the ShopinvaderApiCartRouterHelper to add support for your options in the cart line creation from the transaction API:

class ShopinvaderApiCartRouterHelper(
    models.AbstractModel
):  # pylint: disable=consider-merging-classes-inherited
    _inherit = "shopinvader_api_cart.cart_router.helper"

    @api.model
    def _apply_transactions_creating_new_cart_line_prepare_vals(
        self, cart: SaleOrder, transactions: list[CartTransaction], values: dict
    ):
        options = transactions[0].options
        if options:
            values["carving"] = options.engraving
            values["special"] = options.special

        return values

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits

Authors

  • Akretion

Contributors

Maintainers

This module is part of the shopinvader/odoo-shopinvader project on GitHub.

You are welcome to contribute.

Metadata

Release files for odoo-addon-shopinvader-api-cart-options 18.0.1.0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for odoo-addon-shopinvader-api-cart-options 18.0.1.0.0.2
File Interpreter ABI Platform
odoo_addon_shopinvader_api_cart_options-18.0.1.0.0.2-py3-none-any.whl Python 3 none any Details

Release files / odoo_addon_shopinvader_api_cart_options-18.0.1.0.0.2-py3-none-any.whl

Download URL odoo_addon_shopinvader_api_cart_options-18.0.1.0.0.2-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72785e9b8f6dfd09ae3fee0f8319f46a53f0a0958c1fed3202411fe7b4651572
BLAKE2b-256 checksum
How to use checksums
ae64326755338549c1d2ccb52e7ff27f0ecf6160f00748bf8c6bc06562b64e47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

18.0.1.0.0.2 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page