Metadata-Version: 2.1
Name: odoo-addon-search_engine_serializer_pydantic
Version: 18.0.1.0.0.2
Requires-Python: >=3.10
Requires-Dist: odoo-addon-connector_search_engine==18.0.*
Requires-Dist: odoo-addon-pydantic==18.0.*
Requires-Dist: odoo==18.0.*
Requires-Dist: pydantic
Summary: Defines base class for pydantic baser serializer
Home-page: https://github.com/OCA/search-engine
License: AGPL-3
Author: ACSONE SA/NV,Odoo Community Association (OCA)
Author-email: support@odoo-community.org
Classifier: Programming Language :: Python
Classifier: Framework :: Odoo
Classifier: Framework :: Odoo :: 18.0
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Description-Content-Type: text/x-rst

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

================================
Search Engine Serilizer Pydantic
================================

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

.. |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-OCA%2Fsearch--engine-lightgray.png?logo=github
    :target: https://github.com/OCA/search-engine/tree/18.0/search_engine_serializer_pydantic
    :alt: OCA/search-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
    :target: https://translation.odoo-community.org/projects/search-engine-18-0/search-engine-18-0-search_engine_serializer_pydantic
    :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
    :target: https://runboat.odoo-community.org/builds?repo=OCA/search-engine&target_branch=18.0
    :alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module is a technical module that define a new abstract class named
``PydandicModelSerializer`` that inherit from
``odoo.addons.connector_search_engine.tools.serializer.ModelSerializer``

This new class define a new abstract method ``get_model_class``. This
method is used by the index to get the Pydantic model class to use to
generate the json schema.

On the index form, if the serializer is a ``PydanticModelSerializer``, a
field is displayed to display the related json schema and therefore
provide documentation about the fields exported and their
characteristics.

**Table of contents**

.. contents::
   :local:

Use Cases / Context
===================

When you export records to a search engine, it's common to want to
provides documentation about the fields exported and their
characteristics.

When the serializer used to export the records is a Pydantic model, you
can use the json schema generated by Pydantic to provide this
documentation.

Usage
=====

When you define a serializer based on a Pydantic model, your serializer
class must inherit from ``PydanticModelSerializer`` and implement the
method ``get_model_class`` to take advantage of the functionality
provided by this module.

Example:

.. code:: python


   from typing import Type
   from pydantic import BaseModel

   from odoo.addons.search_engine_serialize_pydantic.tools.serializer import (
       PydanticModelSerializer,
   )


   class MyModel(BaseModel):
       name: str
       description: str

       def record_to_model(self, record: Model) -> dict:
           return cls(
               name=record.name,
               description=record.description,
           )

   class MyModelSerializer(PydanticModelSerializer):
       def get_model_class(self) -> Type[MyModel]:
           return MyModel

       def serialize(self, record: Model) -> dict:
           model: MyModel = self.get_model_class().record_to_model(record)
           return model.model_dump()

Known issues / Roadmap
======================

- Add dedicated widget to display in a user friendly way the json schema
  generated by the serializer on the index form.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/search-engine/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/OCA/search-engine/issues/new?body=module:%20search_engine_serializer_pydantic%0Aversion:%2018.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
-------

* ACSONE SA/NV

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

- Laurent Mignon laurent.mignon@acsone.eu (https://www.acsone.eu/)

Other credits
-------------

The development of this module has been financially supported by:

- (ALCYON Belux)[https://www.alcyonbelux.be/fr/]

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

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
   :alt: Odoo Community Association
   :target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-lmignon| image:: https://github.com/lmignon.png?size=40px
    :target: https://github.com/lmignon
    :alt: lmignon

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-lmignon| 

This module is part of the `OCA/search-engine <https://github.com/OCA/search-engine/tree/18.0/search_engine_serializer_pydantic>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
