Files
odoo_source/addons/product/controllers/catalog.py
T
svs-odoo bc01c7bcec [IMP] product,purchase,sale,*: product catalog
This commit makes two major things:

1. Move the product catalog from `sale` to `product`.
It moves the product catalog's code from `sale` to `product` module in
order to be able to use it in other modules.
A mixin, `product.catalog.mixin`, was created for to make other models
catalog compatible.

2. It enables the product's catalog in `purchase`.
In `purchase`, the catalog differs a little bit from `sale`:
- If Unit of Measure is enable, the UoM for each product will appear in
  the catalog;
- If the product purchase's UoM or the purchase order line's UoM is
  different than the default product's UoM, the former one will be
  displayed (in bold so the user can know it's the UoM to refer);
- When opening the product's catalog from a purchase order, the products
  will be filtered by the PO's vendor;
- Some data from the vendor list will be used if appliant: the minimum
  quantity and the price;
- If there is at least one product's packaging, a button will be
  displayed to increase the qty by the packaging's one. If a packaging
  is set on the purchase order line, this one will be used.

task-3373589

Part-of: odoo/odoo#135502
2023-10-26 07:22:56 +00:00

43 lines
1.8 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.http import request, route, Controller
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._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._update_order_line_info(product_id, quantity, **kwargs)