bug Th qt
This commit is contained in:
@@ -1245,19 +1245,20 @@ class SaleLine(metaclass=PoolMeta):
|
||||
def check_pricing(self):
|
||||
if self.price_components:
|
||||
for pc in self.price_components:
|
||||
if not pc.auto:
|
||||
Pricing = Pool().get('pricing.pricing')
|
||||
pricings = Pricing.search(['price_component','=',pc.id],order=[('pricing_date', 'ASC')])
|
||||
if pricings:
|
||||
cumul_qt = Decimal(0)
|
||||
index = 0
|
||||
for pr in pricings:
|
||||
cumul_qt += pr.quantity
|
||||
pr.fixed_qt = cumul_qt
|
||||
pr.fixed_qt_price = pr.get_fixed_price()
|
||||
pr.unfixed_qt = Decimal(pr.sale_line.quantity_theorical) - pr.fixed_qt
|
||||
pr.unfixed_qt_price = pr.fixed_qt_price
|
||||
pr.eod_price = pr.get_eod_price_sale()
|
||||
if not pc.auto:
|
||||
Pricing = Pool().get('pricing.pricing')
|
||||
pricings = Pricing.search(['price_component','=',pc.id],order=[('pricing_date', 'ASC')])
|
||||
if pricings:
|
||||
cumul_qt = Decimal(0)
|
||||
base_quantity = self._get_pricing_base_quantity()
|
||||
index = 0
|
||||
for pr in pricings:
|
||||
cumul_qt += pr.quantity
|
||||
pr.fixed_qt = cumul_qt
|
||||
pr.fixed_qt_price = pr.get_fixed_price()
|
||||
pr.unfixed_qt = base_quantity - pr.fixed_qt
|
||||
pr.unfixed_qt_price = pr.fixed_qt_price
|
||||
pr.eod_price = pr.get_eod_price_sale()
|
||||
if index == len(pricings) - 1:
|
||||
pr.last = True
|
||||
index += 1
|
||||
@@ -1292,9 +1293,9 @@ class SaleLine(metaclass=PoolMeta):
|
||||
i += 1
|
||||
return lprice
|
||||
|
||||
def getnearprice(self,pl,d,t,max_date=None):
|
||||
if pl:
|
||||
pl_sorted = sorted(pl, key=lambda x: x['date'])
|
||||
def getnearprice(self,pl,d,t,max_date=None):
|
||||
if pl:
|
||||
pl_sorted = sorted(pl, key=lambda x: x['date'])
|
||||
pminus = pl_sorted[0]
|
||||
if not max_date:
|
||||
max_date = d.date()
|
||||
@@ -1309,17 +1310,24 @@ class SaleLine(metaclass=PoolMeta):
|
||||
return pminus[t]
|
||||
else:
|
||||
return Decimal(0)
|
||||
pminus = p
|
||||
return pl_sorted[len(pl)-1][t]
|
||||
return Decimal(0)
|
||||
|
||||
def generate_pricing(self,pc,dl,pl):
|
||||
Pricing = Pool().get('pricing.pricing')
|
||||
pricing = Pricing.search(['price_component','=',pc.id])
|
||||
if pricing:
|
||||
Pricing.delete(pricing)
|
||||
cumul_qt = 0
|
||||
index = 0
|
||||
pminus = p
|
||||
return pl_sorted[len(pl)-1][t]
|
||||
return Decimal(0)
|
||||
|
||||
def _get_pricing_base_quantity(self):
|
||||
quantity = self.quantity_theorical
|
||||
if quantity is None:
|
||||
quantity = self.quantity
|
||||
return Decimal(str(quantity or 0))
|
||||
|
||||
def generate_pricing(self,pc,dl,pl):
|
||||
Pricing = Pool().get('pricing.pricing')
|
||||
pricing = Pricing.search(['price_component','=',pc.id])
|
||||
if pricing:
|
||||
Pricing.delete(pricing)
|
||||
base_quantity = self._get_pricing_base_quantity()
|
||||
cumul_qt = 0
|
||||
index = 0
|
||||
dl_sorted = sorted(dl)
|
||||
for d in dl_sorted:
|
||||
if pc.pricing_date and d.date() > pc.pricing_date:
|
||||
@@ -1336,17 +1344,17 @@ class SaleLine(metaclass=PoolMeta):
|
||||
if price > 0:
|
||||
cumul_qt += pc.quota_sale
|
||||
p.fixed_qt = round(Decimal(cumul_qt),4)
|
||||
p.fixed_qt_price = round(Decimal(self.getnearprice(pl,d,'avg',pc.pricing_date)),4)
|
||||
#p.fixed_qt_price = p.get_fixed_price()
|
||||
if p.fixed_qt_price == 0:
|
||||
p.fixed_qt_price = round(Decimal(self.getnearprice(pl,d,'avg_minus_1',pc.pricing_date)),4)
|
||||
p.unfixed_qt = round(Decimal(self.quantity_theorical) - Decimal(cumul_qt),4)
|
||||
if p.unfixed_qt < 0.001:
|
||||
p.unfixed_qt = Decimal(0)
|
||||
p.fixed_qt = Decimal(self.quantity_theorical)
|
||||
if price > 0:
|
||||
logger.info("GENERATE_1:%s",price)
|
||||
p.unfixed_qt_price = price
|
||||
p.fixed_qt_price = round(Decimal(self.getnearprice(pl,d,'avg',pc.pricing_date)),4)
|
||||
#p.fixed_qt_price = p.get_fixed_price()
|
||||
if p.fixed_qt_price == 0:
|
||||
p.fixed_qt_price = round(Decimal(self.getnearprice(pl,d,'avg_minus_1',pc.pricing_date)),4)
|
||||
p.unfixed_qt = round(base_quantity - Decimal(cumul_qt),4)
|
||||
if p.unfixed_qt < 0.001:
|
||||
p.unfixed_qt = Decimal(0)
|
||||
p.fixed_qt = base_quantity
|
||||
if price > 0:
|
||||
logger.info("GENERATE_1:%s",price)
|
||||
p.unfixed_qt_price = price
|
||||
else:
|
||||
pr = Decimal(pc.price_index.get_price(p.pricing_date,self.unit,self.sale.currency,True))
|
||||
pr = round(pr,4)
|
||||
|
||||
Reference in New Issue
Block a user