mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
[FIX] stock_average_daily_sale: include yesterday in calculation
Because of a datetime to date conversion, yesterday was excluded from calculation while being set as a date_to value. With this commit we include all the stock moves until up to 23:59:59 of the previous day.
This commit is contained in:
@@ -168,8 +168,9 @@ class StockAverageDailySale(models.Model):
|
||||
WITH cfg AS (
|
||||
SELECT
|
||||
*,
|
||||
-- end of the analyzed period
|
||||
NOW()::date - '1 day'::interval as date_to,
|
||||
-- end of the analyzed period; NOW() as a date is today at midnight so to include all moves
|
||||
-- from yesterday, moves with date up to `NOW - 1 second` should be included
|
||||
NOW()::date - '1 second'::interval as date_to,
|
||||
-- start of the analyzed period computed from the original cfg
|
||||
(NOW() - (period_value::TEXT || ' ' || period_name::TEXT)::INTERVAL):: date as date_from,
|
||||
-- the number of days between start and end computed by
|
||||
|
||||
@@ -6,7 +6,7 @@ import logging
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from freezegun import freeze_time
|
||||
|
||||
from odoo.fields import Date
|
||||
from odoo.fields import Date, Datetime
|
||||
from odoo.tests.common import SavepointCase
|
||||
|
||||
from .common import CommonAverageSaleTest
|
||||
@@ -37,7 +37,9 @@ class TestAverageSale(CommonAverageSaleTest, SavepointCase):
|
||||
move._action_assign()
|
||||
move.quantity_done = move.product_uom_qty
|
||||
move._action_done()
|
||||
move_2_date = Date.to_string(self.now - relativedelta(weeks=9))
|
||||
# `now` is today at midnight, checking move with `now - 1 second` datetime
|
||||
# to ensure that all moves from yesterday are included in the calculation
|
||||
move_2_date = Datetime.to_string(self.now - relativedelta(seconds=1))
|
||||
with freeze_time(move_2_date):
|
||||
move = self._create_move(self.product_2, self.location_bin_2, 12.0)
|
||||
move._action_confirm()
|
||||
|
||||
Reference in New Issue
Block a user