Pricing bug
This commit is contained in:
@@ -2137,18 +2137,19 @@ class Line(metaclass=PoolMeta):
|
||||
prPrice = self.get_avg(prPrice)
|
||||
self.generate_pricing(pc,apDate,prPrice)
|
||||
|
||||
def get_avg(self,lprice):
|
||||
l = len(lprice)
|
||||
if l > 0 :
|
||||
cumulprice = float(0)
|
||||
i = 1
|
||||
for p in lprice:
|
||||
if i > 1:
|
||||
p['avg_minus_1'] = cumulprice / (i-1)
|
||||
cumulprice += p['price']
|
||||
p['avg'] = cumulprice / i
|
||||
i += 1
|
||||
return lprice
|
||||
def get_avg(self,lprice):
|
||||
l = len(lprice)
|
||||
if l > 0 :
|
||||
cumulprice = Decimal(0)
|
||||
i = 1
|
||||
for p in lprice:
|
||||
if i > 1:
|
||||
p['avg_minus_1'] = cumulprice / (i-1)
|
||||
p['price'] = Decimal(str(p['price'] or 0))
|
||||
cumulprice += p['price']
|
||||
p['avg'] = cumulprice / i
|
||||
i += 1
|
||||
return lprice
|
||||
|
||||
def getnearprice(self,pl,d,t,max_date=None):
|
||||
if pl:
|
||||
|
||||
@@ -1909,11 +1909,12 @@ class SaleLine(metaclass=PoolMeta):
|
||||
def get_avg(self,lprice):
|
||||
l = len(lprice)
|
||||
if l > 0 :
|
||||
cumulprice = float(0)
|
||||
cumulprice = Decimal(0)
|
||||
i = 1
|
||||
for p in lprice:
|
||||
if i > 1:
|
||||
p['avg_minus_1'] = cumulprice / (i-1)
|
||||
p['price'] = Decimal(str(p['price'] or 0))
|
||||
cumulprice += p['price']
|
||||
p['avg'] = cumulprice / i
|
||||
i += 1
|
||||
|
||||
@@ -1616,6 +1616,36 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
])
|
||||
self.assertEqual(len(prices), 3)
|
||||
|
||||
def test_purchase_line_get_avg_accepts_decimal_matrix_prices(self):
|
||||
'purchase pricing averages Decimal matrix prices without float mixing'
|
||||
PurchaseLine = Pool().get('purchase.line')
|
||||
line = PurchaseLine()
|
||||
prices = [
|
||||
{'price': Decimal('45.0000')},
|
||||
{'price': Decimal('55.0000')},
|
||||
]
|
||||
|
||||
result = line.get_avg(prices)
|
||||
|
||||
self.assertEqual(result[0]['avg'], Decimal('45.0000'))
|
||||
self.assertEqual(result[1]['avg_minus_1'], Decimal('45.0000'))
|
||||
self.assertEqual(result[1]['avg'], Decimal('50.0000'))
|
||||
|
||||
def test_sale_line_get_avg_accepts_decimal_matrix_prices(self):
|
||||
'sale pricing averages Decimal matrix prices without float mixing'
|
||||
SaleLine = Pool().get('sale.line')
|
||||
line = SaleLine()
|
||||
prices = [
|
||||
{'price': Decimal('45.0000')},
|
||||
{'price': Decimal('55.0000')},
|
||||
]
|
||||
|
||||
result = line.get_avg(prices)
|
||||
|
||||
self.assertEqual(result[0]['avg'], Decimal('45.0000'))
|
||||
self.assertEqual(result[1]['avg_minus_1'], Decimal('45.0000'))
|
||||
self.assertEqual(result[1]['avg'], Decimal('50.0000'))
|
||||
|
||||
def test_pricing_trigger_manual_application_defaults_to_pricing_from_to(self):
|
||||
'empty manual application From/To falls back to manual pricing From/To'
|
||||
Trigger = Pool().get('pricing.trigger')
|
||||
|
||||
Reference in New Issue
Block a user