[FIX] product_visible_discount: fix display of unit price according to rule base price like in 7.0 as requested by gab
This commit is contained in:
parent
32bbc34458
commit
2cde5596b9
|
@ -168,6 +168,9 @@ class product_pricelist(osv.osv):
|
|||
}
|
||||
|
||||
def price_get_multi(self, cr, uid, ids, products_by_qty_by_partner, context=None):
|
||||
return dict((key, price[0]) for key, price in self.price_rule_get_multi(cr, uid, ids, products_by_qty_by_partner, context=context).items())
|
||||
|
||||
def price_rule_get_multi(self, cr, uid, ids, products_by_qty_by_partner, context=None):
|
||||
"""multi products 'price_get'.
|
||||
@param ids:
|
||||
@param products_by_qty:
|
||||
|
@ -180,13 +183,16 @@ class product_pricelist(osv.osv):
|
|||
ids = self.pool.get('product.pricelist').search(cr, uid, [], context=context)
|
||||
results = {}
|
||||
for pricelist in self.browse(cr, uid, ids, context=context):
|
||||
subres = self._price_get_multi(cr, uid, pricelist, products_by_qty_by_partner, context=context)
|
||||
subres = self._price_rule_get_multi(cr, uid, pricelist, products_by_qty_by_partner, context=context)
|
||||
for product_id,price in subres.items():
|
||||
results.setdefault(product_id, {})
|
||||
results[product_id][pricelist.id] = price
|
||||
return results
|
||||
|
||||
def _price_get_multi(self, cr, uid, pricelist, products_by_qty_by_partner, context=None):
|
||||
return dict((key, price[0]) for key, price in self._price_rule_get_multi(cr, uid, pricelist, products_by_qty_by_partner, context=context).items())
|
||||
|
||||
def _price_rule_get_multi(self, cr, uid, pricelist, products_by_qty_by_partner, context=None):
|
||||
context = context or {}
|
||||
date = context.get('date') or time.strftime('%Y-%m-%d')
|
||||
|
||||
|
@ -243,6 +249,7 @@ class product_pricelist(osv.osv):
|
|||
uom_price_already_computed = False
|
||||
results[product.id] = 0.0
|
||||
price = False
|
||||
rule_id = False
|
||||
for rule in items:
|
||||
if rule.min_quantity and qty<rule.min_quantity:
|
||||
continue
|
||||
|
@ -313,6 +320,7 @@ class product_pricelist(osv.osv):
|
|||
price = max(price, price_limit+rule.price_min_margin)
|
||||
if rule.price_max_margin:
|
||||
price = min(price, price_limit+rule.price_max_margin)
|
||||
rule_id = rule.id
|
||||
break
|
||||
|
||||
if price:
|
||||
|
@ -320,12 +328,15 @@ class product_pricelist(osv.osv):
|
|||
uom = product.uos_id or product.uom_id
|
||||
price = product_uom_obj._compute_price(cr, uid, uom.id, price, context['uom'])
|
||||
|
||||
results[product.id] = price
|
||||
results[product.id] = (price, rule_id)
|
||||
return results
|
||||
|
||||
def price_get(self, cr, uid, ids, prod_id, qty, partner=None, context=None):
|
||||
return dict((key, price[0]) for key, price in self.price_rule_get(cr, uid, ids, prod_id, qty, partner=partner, context=context).items())
|
||||
|
||||
def price_rule_get(self, cr, uid, ids, prod_id, qty, partner=None, context=None):
|
||||
product = self.pool.get('product.product').browse(cr, uid, prod_id, context=context)
|
||||
res_multi = self.price_get_multi(cr, uid, ids, products_by_qty_by_partner=[(product, qty, partner)], context=context)
|
||||
res_multi = self.price_rule_get_multi(cr, uid, ids, products_by_qty_by_partner=[(product, qty, partner)], context=context)
|
||||
res = res_multi[prod_id]
|
||||
return res
|
||||
|
||||
|
|
|
@ -47,6 +47,11 @@ class sale_order_line(osv.osv):
|
|||
price_type_obj = self.pool.get('product.price.type')
|
||||
product_obj = self.pool.get('product.product')
|
||||
field_name = 'list_price'
|
||||
rule_id = res_dict.get(pricelist) and res_dict[pricelist][1] or False
|
||||
if rule_id:
|
||||
item_base = item_obj.read(cr, uid, [rule_id], ['base'])[0]['base']
|
||||
if item_base > 0:
|
||||
field_name = price_type_obj.browse(cr, uid, item_base).field
|
||||
|
||||
product = product_obj.browse(cr, uid, product_id, context)
|
||||
product_read = product_obj.read(cr, uid, [product_id], [field_name], context=context)[0]
|
||||
|
@ -74,13 +79,14 @@ class sale_order_line(osv.osv):
|
|||
return res
|
||||
|
||||
product = product_obj.browse(cr, uid, product, context)
|
||||
list_price = pricelist_obj.price_get(cr, uid, [pricelist],
|
||||
product.id, qty or 1.0, partner_id, {'uom': uom,'date': date_order })
|
||||
pricelist_context = dict(context, uom=uom, date=date_order)
|
||||
list_price = pricelist_obj.price_rule_get(cr, uid, [pricelist],
|
||||
product.id, qty or 1.0, partner_id, context=pricelist_context)
|
||||
|
||||
so_pricelist = pricelist_obj.browse(cr, uid, pricelist, context=context)
|
||||
|
||||
new_list_price = get_real_price(list_price, product.id, qty, uom, pricelist)
|
||||
if so_pricelist.visible_discount and list_price[pricelist] != 0 and new_list_price != 0:
|
||||
if so_pricelist.visible_discount and list_price[pricelist][0] != 0 and new_list_price != 0:
|
||||
if product.company_id and so_pricelist.currency_id.id != product.company_id.currency_id.id:
|
||||
# new_list_price is in company's currency while price in pricelist currency
|
||||
ctx = context.copy()
|
||||
|
|
Loading…
Reference in New Issue