mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[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:
@@ -85,14 +85,14 @@ class StockDemandEstimate(models.Model):
|
|||||||
rec.date_from = rec.manual_date_from or today
|
rec.date_from = rec.manual_date_from or today
|
||||||
if rec.manual_date_to:
|
if rec.manual_date_to:
|
||||||
rec.date_to = 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:
|
elif rec.manual_duration:
|
||||||
rec.date_to = rec.date_from + timedelta(
|
rec.date_to = rec.date_from + timedelta(
|
||||||
days=rec.manual_duration)
|
days=rec.manual_duration - 1)
|
||||||
rec.duration = rec.manual_duration
|
rec.duration = rec.manual_duration
|
||||||
else:
|
else:
|
||||||
rec.date_to = rec.date_from + timedelta(days=1)
|
rec.date_to = rec.date_from + timedelta(days=1)
|
||||||
rec.duration = 1
|
rec.duration = 2
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.depends("product_qty", "duration")
|
@api.depends("product_qty", "duration")
|
||||||
@@ -138,14 +138,14 @@ class StockDemandEstimate(models.Model):
|
|||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.manual_date_from:
|
if rec.manual_date_from:
|
||||||
rec.manual_duration = (
|
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")
|
@api.onchange("manual_duration")
|
||||||
def _onchange_manual_duration(self):
|
def _onchange_manual_duration(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.manual_date_from:
|
if rec.manual_date_from:
|
||||||
rec.manual_date_to = rec.manual_date_from + timedelta(
|
rec.manual_date_to = rec.manual_date_from + timedelta(
|
||||||
days=rec.manual_duration)
|
days=rec.manual_duration - 1)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def get_quantity_by_date_range(self, date_start, date_end):
|
def get_quantity_by_date_range(self, date_start, date_end):
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class TestStockDemandEstimate(SavepointCase):
|
|||||||
def test_01_create_estimate(self):
|
def test_01_create_estimate(self):
|
||||||
"""Crete an estimate entering manually the date from and date to."""
|
"""Crete an estimate entering manually the date from and date to."""
|
||||||
date_from = date.today() + td(days=10)
|
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({
|
estimate = self.estimate_model.create({
|
||||||
"product_id": self.product_1.id,
|
"product_id": self.product_1.id,
|
||||||
"location_id": self.location.id,
|
"location_id": self.location.id,
|
||||||
@@ -90,7 +90,7 @@ class TestStockDemandEstimate(SavepointCase):
|
|||||||
"product_uom": self.uom_dozen.id,
|
"product_uom": self.uom_dozen.id,
|
||||||
})
|
})
|
||||||
self.assertEqual(estimate.date_from, date_from)
|
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.date_to, expected_date_to)
|
||||||
self.assertEqual(estimate.duration, 15)
|
self.assertEqual(estimate.duration, 15)
|
||||||
expected_qty = 100 * 12.0 # 100 dozens -> units
|
expected_qty = 100 * 12.0 # 100 dozens -> units
|
||||||
@@ -99,7 +99,7 @@ class TestStockDemandEstimate(SavepointCase):
|
|||||||
|
|
||||||
def test_03_get_qty_by_range(self):
|
def test_03_get_qty_by_range(self):
|
||||||
date_from = date.today() + td(days=10)
|
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({
|
estimate = self.estimate_model.create({
|
||||||
"product_id": self.product_1.id,
|
"product_id": self.product_1.id,
|
||||||
"location_id": self.location.id,
|
"location_id": self.location.id,
|
||||||
@@ -107,10 +107,19 @@ class TestStockDemandEstimate(SavepointCase):
|
|||||||
"manual_date_to": date_to,
|
"manual_date_to": date_to,
|
||||||
"product_uom_qty": 100.0,
|
"product_uom_qty": 100.0,
|
||||||
})
|
})
|
||||||
|
self.assertEqual(estimate.duration, 10.0)
|
||||||
self.assertEqual(estimate.daily_qty, 10.0)
|
self.assertEqual(estimate.daily_qty, 10.0)
|
||||||
res = estimate.get_quantity_by_date_range(
|
res = estimate.get_quantity_by_date_range(
|
||||||
date_from + td(days=3), date_from + td(days=17))
|
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(
|
res = estimate.get_quantity_by_date_range(
|
||||||
date_from + td(days=3), date_from + td(days=7))
|
date_from + td(days=3), date_from + td(days=7))
|
||||||
self.assertEqual(res, 50)
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user