获取给定客户的产品价格的方法 [英] Method to get product price for a given customer
问题描述
我需要通过 XMLRPC 检索产品价格.
I need to retrieve product price via XMLRPC.
我正在使用产品价目表,因此可以为每个客户分配一个给定的价目表,该价目表根据类别等提供特定折扣.
I am using Product Price Lists so each customer can be assigned a given price list which gives specific discounts based on categories, etc.
我正在努力寻找可以使用哪种方法来检索给定数量的给定 product_template
id 的价格(如果确实可能的话).
I am struggling to find which method can be used to retrieve the price for a given product_template
id at a given quantity, if that is actually possible.
到目前为止,我还没有尝试任何特定的方法,因为我无法确定如何在不实际创建销售订单的情况下实现这一点.
So far I have not been able to try any specific method as I can not identify how can this be achieved without actually creating a sales order.
推荐答案
'product' 模块包含价格表机制.模型 product.pricelist
有一个非常好的方法 get_product_price()
,它可以很容易地在服务器端使用,但不能用于外部/网络 API.
The module 'product' holds the pricelist mechanics. The model product.pricelist
has a really nice method get_product_price()
, which could be easily used server-side but not for the external/web API.
但如果您有可能编写一个小的自定义模块,请执行此操作并覆盖模型 product.pricelist
.添加使用此方法的可能性,例如:
But if you have the possibility to write a little custom module, do that and override the model product.pricelist
. Add the possibility to use this method, like:
无法使用的Origin方法,因为参数是RecordSets:
Origin Method which can't be used because parameters are RecordSets:
def get_product_price(self, product, quantity, partner, date=False, uom_id=False):
""" For a given pricelist, return price for a given product """
self.ensure_one()
return self._compute_price_rule([(product, quantity, partner)], date=date, uom_id=uom_id)[product.id][0]
用于外部/网络 API 的包装器":
"Wrapper" for external/web API:
def web_api_get_product_price(
self, product_id, quantity, partner_id, date=False, uom_id=False):
""" For a given pricelist, return price for a given product
callable from web api"""
self.ensure_one()
# get records
product = self.env['product.product'].browse(product_id)
partner = self.env['res.partner'].browse(partner_id)
# call origin method
return self.get_product_price(
product, quantity, partner, date=date, uom_id=uom_id)
现在可以调用这个方法了,一个例子:
Now you can call this method, an example:
import xmlrpclib
db = 'db_name'
password = 'admin'
common = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/2/common')
uid = common.authenticate(db, 'admin', password, {})
models = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/2/object')
pricelist_id = 1
product_id = 5
partner_id = 7
quantity = 20
price = models.execute_kw(
db, uid, password, 'product.pricelist',
'web_api_get_product_price',
[[pricelist_id], product_id, quantity, partner_id], {})
这篇关于获取给定客户的产品价格的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!