Module 在openerp中,如何覆盖产品的基本标价?
我有OpenERP外部的代码,可以作为现有的产品定价系统使用。我们的每种产品都有一个基价,这个基价是以一种比较复杂的方式确定的 此外部系统通过RPC api在OpenERP中管理和创建销售订单 我们想从外部定价系统中删除计算价格信息的代码,/after/it已经确定了基价。也就是说,在OpenERP术语中,每种产品都有(比如)十种不同的标价 从这里开始,我们将使用OpenERP的价格表系统对该基准价格进行进一步计算 目前,我有向OpenERP询问产品价格的代码:Module 在openerp中,如何覆盖产品的基本标价?,module,overriding,product,openerp,Module,Overriding,Product,Openerp,我有OpenERP外部的代码,可以作为现有的产品定价系统使用。我们的每种产品都有一个基价,这个基价是以一种比较复杂的方式确定的 此外部系统通过RPC api在OpenERP中管理和创建销售订单 我们想从外部定价系统中删除计算价格信息的代码,/after/it已经确定了基价。也就是说,在OpenERP术语中,每种产品都有(比如)十种不同的标价 从这里开始,我们将使用OpenERP的价格表系统对该基准价格进行进一步计算 目前,我有向OpenERP询问产品价格的代码: ... date_ord
...
date_order = time.strftime(DEFAULT_SERVER_DATE_FORMAT) #Pricelists are seasonal
price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist_id], product.id, qty, partner.id, {
'uom': uom,
'date': date_order,
})[pricelist_id]
...
price_taxes = tax_obj.compute_all(cr, uid, tax_objs, price, qty, billing_addr.id, product.id, partner.id)
这是正确的,给了我一个特定产品的价格
pricelist树(因为pricelists可以基于彼此等)最终调用product\u product.price\u get(self、cr、uid、ids、ptype='list\u price',context=None)
通过self.browse(…)[ptype]
读取列表价格
我认为最简单的修改方法是对product.list\u price进行按请求覆盖。我的意思是创建一个在上下文中设置变量的rpc方法,并修改price_get以读取上下文变量而不是产品对象
另一种选择是使用本地线程,但这仍然是对price_get函数的修改
我正在考虑重写列定义并添加一个getter方法,但我不确定它是否会从self.browse调用中使用
你推荐什么?覆盖price\u get
,覆盖列list\u price
,还是其他什么
谢谢你的帮助。我这样解决了我的问题:
class product_product(osv.osv):
def _get_dyn_list_price(self, cr, uid, ids, field_name, arg, context):
res = {}
b = self.browse(cr, uid, ids)
for obj in b:
res[obj.id] = context.get('dyn_prices', {}).get(obj.id, None)
return res
_name = _inherit = 'product.product'
_columns = {
'dynamic_list_price': fields.function(_get_dyn_list_price, type='float', method=True, string='Dynamic List Price', store=False, digits_compute=dp.get_precision('Sale Price'), help="Dynamic base price for product after applying door styles, etc.", readonly=True),
}
def price_get(self, cr, uid, ids, ptype='list_price', context=None):
if ptype != 'list_price':
return super(product_product, self).price_get(cr, uid, ids, ptype, context)
ptype = 'dynamic_list_price' #Will cause price_margin / price_extra to not be respected
res = super(product_product, self).price_get(cr, uid, ids, ptype, context)
for k, v in res.iteritems():
if v is None:
if context.get('require_dyn_prices', False):
raise osv.except_osv('Error !', 'Dynamic prices required, but product ID not found in context.')
res[k] = super(product_product, self).price_get(cr, uid, [k], ptype, context)[k]
return res
date_order = time.strftime(DEFAULT_SERVER_DATE_FORMAT) #Pricelists are seasonal
price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist_id], product.id, qty, partner.id, {
'uom': uom,
'date': date_order,
'dyn_prices': {product.id: unit_price},
'require_dyn_prices': True,
})[pricelist_id]
然后可以这样使用:
class product_product(osv.osv):
def _get_dyn_list_price(self, cr, uid, ids, field_name, arg, context):
res = {}
b = self.browse(cr, uid, ids)
for obj in b:
res[obj.id] = context.get('dyn_prices', {}).get(obj.id, None)
return res
_name = _inherit = 'product.product'
_columns = {
'dynamic_list_price': fields.function(_get_dyn_list_price, type='float', method=True, string='Dynamic List Price', store=False, digits_compute=dp.get_precision('Sale Price'), help="Dynamic base price for product after applying door styles, etc.", readonly=True),
}
def price_get(self, cr, uid, ids, ptype='list_price', context=None):
if ptype != 'list_price':
return super(product_product, self).price_get(cr, uid, ids, ptype, context)
ptype = 'dynamic_list_price' #Will cause price_margin / price_extra to not be respected
res = super(product_product, self).price_get(cr, uid, ids, ptype, context)
for k, v in res.iteritems():
if v is None:
if context.get('require_dyn_prices', False):
raise osv.except_osv('Error !', 'Dynamic prices required, but product ID not found in context.')
res[k] = super(product_product, self).price_get(cr, uid, [k], ptype, context)[k]
return res
date_order = time.strftime(DEFAULT_SERVER_DATE_FORMAT) #Pricelists are seasonal
price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist_id], product.id, qty, partner.id, {
'uom': uom,
'date': date_order,
'dyn_prices': {product.id: unit_price},
'require_dyn_prices': True,
})[pricelist_id]
祝贺你:)但是你的问题很难理解。也许你可以更详细地解释一下,这样我们都可以从中学习。基本上,我有一些产品变体,它们不会直接影响OpenERP的库存系统,它们确实会影响价格。价格是从外部计算的,但我想通过OpenERP的pricelist功能传递它。上面的代码做到了这一点,所需的黑客比我最初认为的要少。“return super(product\u product,self).price\u get(cr,uid,ids,ptype,context)”:您不能使用父产品的price\u get(),因为您的类是从osv.osv继承的。那这是怎么回事?我想你回答错地方了。如果你的意思是在下面,我没有得到那个错误,也不知道那是从哪里来的。我在6.0上开发了这个,它在那里工作。