[12.0][FIX] stock_demand_estimate: duration wrongly interpreted, if you have a period from today to tomorrow, duration is 2 not 1.

This commit is contained in:
Lois Rilo
2019-12-31 16:17:21 +01:00
committed by davidborromeo
parent 28b6ab3d5c
commit d9516b86c2
2 changed files with 18 additions and 9 deletions

View File

@@ -85,14 +85,14 @@ class StockDemandEstimate(models.Model):
rec.date_from = rec.manual_date_from or today
if rec.manual_date_to:
rec.date_to = rec.manual_date_to
rec.duration = (rec.manual_date_to - rec.date_from).days
rec.duration = (rec.manual_date_to - rec.date_from).days + 1
elif rec.manual_duration:
rec.date_to = rec.date_from + timedelta(
days=rec.manual_duration)
days=rec.manual_duration - 1)
rec.duration = rec.manual_duration
else:
rec.date_to = rec.date_from + timedelta(days=1)
rec.duration = 1
rec.duration = 2
@api.multi
@api.depends("product_qty", "duration")
@@ -138,14 +138,14 @@ class StockDemandEstimate(models.Model):
for rec in self:
if rec.manual_date_from:
rec.manual_duration = (
rec.manual_date_to - rec.manual_date_from).days
rec.manual_date_to - rec.manual_date_from).days + 1
@api.onchange("manual_duration")
def _onchange_manual_duration(self):
for rec in self:
if rec.manual_date_from:
rec.manual_date_to = rec.manual_date_from + timedelta(
days=rec.manual_duration)
days=rec.manual_duration - 1)
@api.model
def get_quantity_by_date_range(self, date_start, date_end):

View File

@@ -63,7 +63,7 @@ class TestStockDemandEstimate(SavepointCase):
def test_01_create_estimate(self):
"""Crete an estimate entering manually the date from and date to."""
date_from = date.today() + td(days=10)
date_to = date.today() + td(days=20)
date_to = date.today() + td(days=19)
estimate = self.estimate_model.create({
"product_id": self.product_1.id,
"location_id": self.location.id,
@@ -90,7 +90,7 @@ class TestStockDemandEstimate(SavepointCase):
"product_uom": self.uom_dozen.id,
})
self.assertEqual(estimate.date_from, date_from)
expected_date_to = estimate.date_from + td(days=15)
expected_date_to = estimate.date_from + td(days=15 - 1)
self.assertEqual(estimate.date_to, expected_date_to)
self.assertEqual(estimate.duration, 15)
expected_qty = 100 * 12.0 # 100 dozens -> units
@@ -99,7 +99,7 @@ class TestStockDemandEstimate(SavepointCase):
def test_03_get_qty_by_range(self):
date_from = date.today() + td(days=10)
date_to = date.today() + td(days=20)
date_to = date.today() + td(days=19)
estimate = self.estimate_model.create({
"product_id": self.product_1.id,
"location_id": self.location.id,
@@ -107,10 +107,19 @@ class TestStockDemandEstimate(SavepointCase):
"manual_date_to": date_to,
"product_uom_qty": 100.0,
})
self.assertEqual(estimate.duration, 10.0)
self.assertEqual(estimate.daily_qty, 10.0)
res = estimate.get_quantity_by_date_range(
date_from + td(days=3), date_from + td(days=17))
self.assertEqual(res, 80)
self.assertEqual(res, 70)
res = estimate.get_quantity_by_date_range(
date_from + td(days=3), date_from + td(days=7))
self.assertEqual(res, 50)
# get full period
res = estimate.get_quantity_by_date_range(
date.today(), date_from + td(days=17))
self.assertEqual(res, 100)
# Get exact period:
res = estimate.get_quantity_by_date_range(
estimate.date_from, estimate.date_to)
self.assertEqual(res, 100)