Hi Daniel
price_get has been changed to _get_products_price for list of product and get_product_price for one specific product (im product.pricelist model)
As this methods are private, you may create a method callable from Api that will call this private method
here an example
# In a custom Odoo module
from odoo import models, fields
class ProductPricelist(models.Model):
_inherit = 'product.pricelist'
def get_pricelist_price_webhook(self, pricelist_id, product_ids, quantity):
pricelist = self.browse(pricelist_id)
prices = {}
for product in self.env['product.product'].browse(product_ids):
prices[product.id] = pricelist._get_product_price(product, quantity, self.env.user.partner_id)
return prices
With token
from odoo import models, api, _, exceptions
import logging
_logger = logging.getLogger(__name__)
class ProductPricelist(models.Model):
_inherit = 'product.pricelist'
def get_products_price(self, product_ids, quantity=1, partner_id=None, token=None):
"""
Public method to safely retrieve prices for a list of products based on the pricelist,
quantity, and partner context. This method wraps the private `_get_products_price`
to provide secure access with token verification.
:param product_ids: List of product IDs for which prices are to be fetched.
:param quantity: Quantity for each product; defaults to 1.
:param partner_id: Optional partner ID for partner-specific pricing.
:param token: Security token to authorize access.
:return: Dictionary with product IDs as keys and computed prices as values.
"""
# Validate token
token = request.env['ir.config_parameter'].sudo().get_param('your_custom_module.token')
if not token or token != token:
_logger.warning("Unauthorized access attempt with invalid token.")
raise exceptions.AccessDenied(_("Invalid token provided. Access denied."))
self.ensure_one()
# Retrieve partner record if partner_id is provided
partner = self.env['res.partner'].browse(partner_id) if partner_id else None
# Retrieve the product records based on provided product IDs
products = self.env['product.product'].browse(product_ids)
# Prepare quantities list to match the number of products
quantities = [quantity] * len(products)
# Call the private `_get_products_price` method
try:
prices = self._get_products_price(products, quantities, partner)
except Exception as e:
# Log error for debugging purposes if the private method fails
_logger.error(f"Error retrieving prices: {e}")
return {}
# Return prices in a dictionary format, ensuring prices align with product IDs
price_dict = {product.id: prices[product.id] for product in products}
return price_dict
hope this helps
Daniel
Thanks Daniel,
Actually I found a couple of samples and I developed Python before, so the code is pretty clear (sorry for no clarifying). My main question, how can I deploy this code? We're using the regular Odoo subscription. Not sure if this is possible... do we need a custom server running Python and then upload a code main branch?
Thanks!