Add product options to the cart API
Project description
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
Contributors
Florian Mounier florian.mounier@akretion.com
Maintainers
This module is part of the shopinvader/odoo-shopinvader project on GitHub.
You are welcome to contribute.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file odoo_addon_shopinvader_api_cart_options-16.0.1.0.1-py3-none-any.whl.
File metadata
- Download URL: odoo_addon_shopinvader_api_cart_options-16.0.1.0.1-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f963402315e52a304857f6043ba4a38c129c8ce7e6d210ba4ffe578e6b176169
|
|
| MD5 |
e562cfc2817163f42e7770558ecbe51a
|
|
| BLAKE2b-256 |
3fd52f4f9b2acf1cce863e164cb2dee4b46c72c21a4b22d70eb27092dd9f31f3
|