Skip to content

Commit

Permalink
[ADD] shopinvader_search_engine_product_multi_price
Browse files Browse the repository at this point in the history
  • Loading branch information
qgroulard committed Jun 4, 2024
1 parent 13876c4 commit 005e5ff
Show file tree
Hide file tree
Showing 19 changed files with 703 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/shopinvader_search_engine_product_multi_price/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
71 changes: 71 additions & 0 deletions shopinvader_search_engine_product_multi_price/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
=============================================
Shopinvader Search Engine Product Multi Price
=============================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:05a73ae4cb7fb4ac83a7800fcb3c61a917f562b886794ae028384f1e1675f201
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-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_search_engine_product_multi_price
:alt: shopinvader/odoo-shopinvader

|badge1| |badge2| |badge3|

Adds prices to the export of products for Shopinvader.
One price is exported per pricelist set on the index.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Usage
=====

Set pricelists per index or on the search engine backend to apply globally.

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_search_engine_product_multi_price%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
~~~~~~~

* ACSONE SA/NV

Contributors
~~~~~~~~~~~~

* Quentin Groulard <[email protected]>

Maintainers
~~~~~~~~~~~

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

You are welcome to contribute.
2 changes: 2 additions & 0 deletions shopinvader_search_engine_product_multi_price/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import schemas
16 changes: 16 additions & 0 deletions shopinvader_search_engine_product_multi_price/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Shopinvader Search Engine Product Multi Price",
"summary": "Add the export of multiple prices for Shopinvader",
"version": "16.0.1.0.0",
"category": "e-commerce",
"license": "AGPL-3",
"author": "ACSONE SA/NV",
"website": "https://github.com/shopinvader/odoo-shopinvader",
"depends": ["product_get_price_helper", "shopinvader_search_engine"],
"data": ["views/se_backend.xml", "views/se_index.xml"],
"demo": [],
"development_status": "Alpha",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import product_product
from . import se_backend
from . import se_index
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ProductProduct(models.Model):
_inherit = "product.product"

shopinvader_price_by_pricelist = fields.Json(
compute="_compute_shopinvader_price_by_pricelist"
)

@api.depends_context("index_id")
def _compute_shopinvader_price_by_pricelist(self):
index_id = self.env.context.get("index_id", False)
index = self.env["se.index"].browse(index_id)
for product in self:
prices = {}
if index_id:
for pricelist in index._get_pricelists():
price = product._get_price(pricelist=pricelist)
prices.update({pricelist.id: price})
product.shopinvader_price_by_pricelist = prices
11 changes: 11 additions & 0 deletions shopinvader_search_engine_product_multi_price/models/se_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class SeBackend(models.Model):

_inherit = "se.backend"

pricelist_ids = fields.Many2many("product.pricelist", string="Pricelists")
20 changes: 20 additions & 0 deletions shopinvader_search_engine_product_multi_price/models/se_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class SeIndex(models.Model):

_inherit = "se.index"

pricelist_ids = fields.Many2many(
comodel_name="product.pricelist",
string="Pricelists",
help="Define pricelists for price computation, "
"keep empty to take configuration from the backend",
)

def _get_pricelists(self):
self.ensure_one()
return self.pricelist_ids or self.backend_id.pricelist_ids
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Quentin Groulard <[email protected]>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Adds prices to the export of products for Shopinvader.
One price is exported per pricelist set on the index.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set pricelists per index or on the search engine backend to apply globally.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .product import ProductPriceInfo, ProductProduct
23 changes: 23 additions & 0 deletions shopinvader_search_engine_product_multi_price/schemas/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from extendable_pydantic import StrictExtendableBaseModel

from odoo.addons.shopinvader_product.schemas import ProductProduct as BaseProduct


class ProductPriceInfo(StrictExtendableBaseModel):
value: float = 0
tax_included: bool = False
original_value: float = 0
discount: float = 0


class ProductProduct(BaseProduct, extends=True):
price_by_pricelist: dict[int, ProductPriceInfo] = {}

@classmethod
def from_product_product(cls, odoo_rec):
obj = super().from_product_product(odoo_rec)
obj.price_by_pricelist = odoo_rec.shopinvader_price_by_pricelist or {}
return obj
Loading

0 comments on commit 005e5ff

Please sign in to comment.