Metadata-Version: 2.1
Name: odoo-addon-shopinvader_api_cart_options
Version: 16.0.1.0.2
Summary: Add product options to the cart API
Home-page: https://github.com/shopinvader/odoo-shopinvader
Author: Akretion, Odoo Community Association (OCA)
Author-email: support@odoo-community.org
License: AGPL-3
Classifier: Programming Language :: Python
Classifier: Framework :: Odoo
Classifier: Framework :: Odoo :: 16.0
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Requires-Python: >=3.10
Requires-Dist: odoo-addon-shopinvader-api-cart<16.1dev,>=16.0dev
Requires-Dist: odoo<16.1dev,>=16.0a

.. image:: https://odoo-community.org/readme-banner-image
   :target: https://odoo-community.org/get-involved?utm_source=readme
   :alt: Odoo Community Association

============================
Shopinvader API Cart Options
============================

.. 
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! This file is generated by oca-gen-addon-readme !!
   !! changes will be overwritten.                   !!
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! source digest: sha256:b74c2fe5927282e27e55a0c35b0d40c938deddfdbad9ce867f09c254bc4281ab
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
    :target: https://odoo-community.org/page/development-status
    :alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
    :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
    :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-shopinvader%2Fodoo--shopinvader-lightgray.png?logo=github
    :target: https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_api_cart_options
    :alt: shopinvader/odoo-shopinvader

|badge1| |badge2| |badge3|

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**

.. contents::
   :local:

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:

.. code:: python

   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:

.. code:: python

   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:

.. code:: python

   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 <https://github.com/shopinvader/odoo-shopinvader/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 <https://github.com/shopinvader/odoo-shopinvader/issues/new?body=module:%20shopinvader_api_cart_options%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Akretion

Contributors
------------

- Florian Mounier florian.mounier@akretion.com

Maintainers
-----------

This module is part of the `shopinvader/odoo-shopinvader <https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_api_cart_options>`_ project on GitHub.

You are welcome to contribute.
