-
-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport from the v17 functionality TT50477
- Loading branch information
1 parent
71f6fcf
commit 16a23a6
Showing
29 changed files
with
1,558 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
=============== | ||
Product Catalog | ||
=============== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:3d34fa62aed534517dd4da5bbb4a76ef626aa74cd47b3bd7a0c726c8d7de853e | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/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-OCA%2Fproduct--attribute-lightgray.png?logo=github | ||
:target: https://github.com/OCA/product-attribute/tree/16.0/product_catalog | ||
:alt: OCA/product-attribute | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-product_catalog | ||
: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/product-attribute&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
A backport of Odoo's v17 Product Catalog. | ||
|
||
Changes over mainstream: | ||
|
||
:: | ||
|
||
- Price is an optional value now so we can use it in other models. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Use Cases / Context | ||
=================== | ||
|
||
The product catalog is a nice addon the version 17 features that allows | ||
users to use a simple product picker to quickly add products to a | ||
document (sale or purchase order). | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
1. Go to ... | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
- Be able to filter just the added products. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/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/product-attribute/issues/new?body=module:%20product_catalog%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 | ||
------- | ||
|
||
* Odoo SA | ||
* Tecnativa | ||
|
||
Contributors | ||
------------ | ||
|
||
- `Tecnativa <https://tecnativa.com>`__ | ||
|
||
- David Vidal | ||
|
||
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. | ||
|
||
This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/16.0/product_catalog>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import controllers | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2024 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
{ | ||
"name": "Product Catalog", | ||
"summary": "Backport of Odoos v17 product catalog", | ||
"version": "16.0.1.0.0", | ||
"author": "Odoo SA, Tecnativa, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/product-attribute", | ||
"license": "AGPL-3", | ||
"category": "Product", | ||
"depends": ["product"], | ||
"data": [ | ||
"views/product_views.xml", | ||
], | ||
"demo": [], | ||
"assets": { | ||
"web.assets_backend": [ | ||
"product_catalog/static/src/product_catalog/**/*.js", | ||
"product_catalog/static/src/product_catalog/**/*.xml", | ||
"product_catalog/static/src/product_catalog/**/*.scss", | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import catalog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from odoo.http import Controller, request, route | ||
|
||
|
||
class ProductCatalogController(Controller): | ||
@route("/product/catalog/order_lines_info", auth="user", type="json") | ||
def product_catalog_get_order_lines_info( | ||
self, res_model, order_id, product_ids, **kwargs | ||
): | ||
"""Returns products information to be shown in the catalog. | ||
:param string res_model: The order model. | ||
:param int order_id: The order id. | ||
:param list product_ids: The products currently displayed in the product | ||
catalog, as a list of `product.product` ids. | ||
:rtype: dict | ||
:return: A dict with the following structure: | ||
{ | ||
product.id: { | ||
'productId': int | ||
'quantity': float (optional) | ||
'price': float | ||
'readOnly': bool (optional) | ||
} | ||
} | ||
""" | ||
order = request.env[res_model].browse(order_id) | ||
return order.with_company( | ||
order.company_id | ||
)._get_product_catalog_order_line_info( | ||
product_ids, | ||
**kwargs, | ||
) | ||
|
||
@route("/product/catalog/update_order_line_info", auth="user", type="json") | ||
def product_catalog_update_order_line_info( | ||
self, res_model, order_id, product_id, quantity=0, **kwargs | ||
): | ||
"""Update order line information on a given order for a given product. | ||
:param string res_model: The order model. | ||
:param int order_id: The order id. | ||
:param int product_id: The product, as a `product.product` id. | ||
:return: The unit price price of the product, based on the pricelist of the order and | ||
the quantity selected. | ||
:rtype: float | ||
""" | ||
order = request.env[res_model].browse(order_id) | ||
return order.with_company(order.company_id)._update_order_line_info( | ||
product_id, | ||
quantity, | ||
**kwargs, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import product_catalog_mixin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from odoo import _, fields, models | ||
|
||
|
||
class ProductCatalogMixin(models.AbstractModel): | ||
"""This mixin should be inherited when the model should be able to work | ||
with the product catalog. | ||
It assumes the model using this mixin has a O2M field where the products are | ||
added/removed and this field's co-related model should has a method named | ||
`_get_product_catalog_lines_data`. | ||
""" | ||
|
||
_name = "product.catalog.mixin" | ||
_description = "Product Catalog Mixin" | ||
|
||
catalog_button_text = fields.Text(compute="_compute_catalog_button_text") | ||
|
||
def _compute_catalog_button_text(self): | ||
quotations = self.filtered(lambda x: x.state in {"draft", "sent"}) | ||
quotations.catalog_button_text = _("Back to Quotation") | ||
(self - quotations).catalog_button_text = _("Back to Order") | ||
|
||
def action_add_from_catalog(self): | ||
kanban_view_id = self.env.ref("product_catalog.product_view_kanban_catalog").id | ||
search_view_id = self.env.ref("product_catalog.product_view_search_catalog").id | ||
additional_context = self._get_action_add_from_catalog_extra_context() | ||
return { | ||
"type": "ir.actions.act_window", | ||
"name": _("Products"), | ||
"res_model": "product.product", | ||
"views": [(kanban_view_id, "kanban"), (False, "form")], | ||
"search_view_id": [search_view_id, "search"], | ||
"domain": self._get_product_catalog_domain(), | ||
"context": {**self.env.context, **additional_context}, | ||
} | ||
|
||
def _default_order_line_values(self): | ||
return { | ||
"quantity": 0, | ||
"readOnly": self._is_readonly() if self else False, | ||
} | ||
|
||
def _get_product_catalog_domain(self): | ||
"""Get the domain to search for products in the catalog. | ||
For a model that uses products that has to be hidden in the catalog, it | ||
must override this method and extend the appropriate domain. | ||
:returns: A list of tuples that represents a domain. | ||
:rtype: list | ||
""" | ||
return [("company_id", "in", [self.company_id.id, False])] | ||
|
||
def _get_product_catalog_record_lines(self, product_ids): | ||
"""Returns the record's lines grouped by product. | ||
Must be overrided by each model using this mixin. | ||
:param list product_ids: The ids of the products currently displayed in the | ||
product catalog. | ||
:rtype: dict | ||
""" | ||
return {} | ||
|
||
def _get_product_catalog_order_data(self, products, **kwargs): | ||
"""Returns a dict containing the products' data. Those data are for products | ||
who aren't in the record yet. For products already in the record, see | ||
`_get_product_catalog_lines_data`. | ||
For each product, its id is the key and the value is another dict with all | ||
needed data. By default, the price is the only needed data but each model is | ||
free to add more data. Must be overrided by each model using this mixin. | ||
:param products: Recordset of `product.product`. | ||
:param dict kwargs: additional values given for inherited models. | ||
:rtype: dict | ||
:return: A dict with the following structure: | ||
{ | ||
'productId': int | ||
'quantity': float (optional) | ||
'productType': string | ||
'price': float | ||
'readOnly': bool (optional) | ||
} | ||
""" | ||
res = {} | ||
for product in products: | ||
res[product.id] = {"productType": product.type} | ||
return res | ||
|
||
def _get_product_catalog_order_line_info(self, product_ids, **kwargs): | ||
"""Returns products information to be shown in the catalog. | ||
:param list product_ids: The products currently displayed in the product | ||
catalog, as a list of `product.product` ids. | ||
:param dict kwargs: additional values given for inherited models. | ||
:rtype: dict | ||
:return: A dict with the following structure: | ||
{ | ||
'productId': int | ||
'quantity': float (optional) | ||
'productType': string | ||
'price': float (optional) | ||
'readOnly': bool (optional) | ||
} | ||
""" | ||
order_line_info = {} | ||
default_data = self._default_order_line_values() | ||
|
||
for product, record_lines in self._get_product_catalog_record_lines( | ||
product_ids | ||
).items(): | ||
order_line_info[product.id] = { | ||
**record_lines._get_product_catalog_lines_data(**kwargs), | ||
"productType": product.type, | ||
} | ||
product_ids.remove(product.id) | ||
|
||
products = self.env["product.product"].browse(product_ids) | ||
product_data = self._get_product_catalog_order_data(products, **kwargs) | ||
for product_id, data in product_data.items(): | ||
order_line_info[product_id] = {**default_data, **data} | ||
return order_line_info | ||
|
||
def _get_action_add_from_catalog_extra_context(self): | ||
return { | ||
"product_catalog_order_id": self.id, | ||
"product_catalog_order_model": self._name, | ||
} | ||
|
||
def _is_readonly(self): | ||
"""Must be overrided by each model using this mixin. | ||
:return: Whether the record is read-only or not. | ||
:rtype: bool | ||
""" | ||
return False | ||
|
||
def _update_order_line_info(self, product_id, quantity, **kwargs): | ||
"""Update the line information for a given product or create a new one if none | ||
exists yet. Must be overrided by each model using this mixin. | ||
:param int product_id: The product, as a `product.product` id. | ||
:param int quantity: The product's quantity. | ||
:param dict kwargs: additional values given for inherited models. | ||
:return: The unit price of the product, based on the pricelist of the | ||
purchase order and the quantity selected. | ||
:rtype: float | ||
""" | ||
return 0 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
The product catalog is a nice addon the version 17 features that allows users to use | ||
a simple product picker to quickly add products to a document (sale or purchase order). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- [Tecnativa](https://tecnativa.com) | ||
- David Vidal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
A backport of Odoo's v17 Product Catalog. | ||
|
||
Changes over mainstream: | ||
|
||
- Price is an optional value now so we can use it in other models. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Be able to filter just the added products. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
To use this module, you need to: | ||
|
||
1. Go to ... |
Oops, something went wrong.