2012-07-10 71 views
1

我拥有OpenERP外部的代码,可用作现有的产品定价系统。我们的每种产品的基本价格都是以一种相当复杂的方式确定的。在openerp中,如何覆盖产品的基本清单价格?

此外部系统通过RPC API在OpenERP中管理和创建销售订单。

我们想从我们的外部定价系统中移除代码,以计算价格信息,/之后/它已经确定了基准价格。也就是说,按照OpenERP的条款,每种产品都有(说)十种不同的目录价格。

从这里,我们想使用OpenERP的价格表系统来预测这个基准价格的进一步计算。

目前,我有一些代码的OpenERP要求对产品价格:

... 
    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) 

这正常工作,并给了我一个特定产品的价格。

价格表树(因为价格表可以基于对方等)最终会调用product_product.price_get(self, cr, uid, ids, ptype='list_price', context=None),它通过self.browse(...)[ptype]读取list_price。

我认为最简单的方法来修改这是product.list_price上的每个请求覆盖。通过这个我的意思是创建一个rpc方法,在上下文中设置一个变量,并修改price_get来读取上下文var而不是产品对象。

另一种选择是使用线程本地,但这仍然是price_get函数的修改。

我想重写列定义并添加一个getter方法,但我不确定它是否会从self.browse调用中使用。

你会推荐什么?覆盖price_get,覆盖列list_price,或其他?

感谢您的帮助。

+0

“返回超(product_product,个体经营).price_get(CR,UID,IDS,p型,context)“:您无法使用父级product_product中的price_get(),因为您的类是从osv.osv继承的。 那么这是如何工作的? – mcmaerti 2012-11-12 14:24:45

+0

我认为你回答了错误的地方。如果你的意思是低于这个意思,我没有得到那个错误,也不知道从哪里来。我在6.0上开发了它,它在那里工作。 – 2012-11-12 20:58:17

回答

2

我解决我的问题是这样的:

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] 
+0

祝贺:)但是,你的问题很难理解。也许你可以更详细地解释它,这样我们都可以从中学习。 – 2012-07-11 03:02:39

+0

从本质上讲,我的产品变体不会直接影响OpenERP的库存管理系统,它们会影响价格。价格是从外部计算的,但我想通过OpenERP的价格表功能。上面的代码用比我最初认为需要的更少的骇客来做这件事。 – 2012-07-11 19:08:51

相关问题