Use today as planned date for assigned move
The inclusion of the assigned move in the computation must be coherent between quantity and delta. Closes #12914 (grafted from 0504da7e1abba6df691519b60c4fa8ac3a54e40a) --HG-- branch : 7.0
This commit is contained in:
1 parent
681443282e
commit
11fa3768bf
2 files changed
+47
-61
No files matched your search
+21
-59
@@ -1283,7 +1283,10 @@ class Move(Workflow, ModelSQL, ModelView):
|
||||
def get_column(name, table):
|
||||
if name == 'date':
|
||||
return cls.effective_date.sql_cast(
|
||||
Coalesce(table.effective_date, table.planned_date))
|
||||
Coalesce(
|
||||
table.effective_date,
|
||||
Case((move.state == 'assigned', today), else_=Null),
|
||||
table.planned_date))
|
||||
else:
|
||||
return Column(table, name)
|
||||
|
||||
@@ -1408,6 +1411,11 @@ class Move(Workflow, ModelSQL, ModelView):
|
||||
if not context.get('stock_date_end'):
|
||||
context['stock_date_end'] = datetime.date.max
|
||||
|
||||
move_date = Coalesce(
|
||||
move.effective_date,
|
||||
Case((move.state == 'assigned', today), else_=Null),
|
||||
move.planned_date)
|
||||
|
||||
# date end in the past or today: filter on state done
|
||||
if (context['stock_date_end'] < today
|
||||
or (context['stock_date_end'] == today
|
||||
@@ -1416,14 +1424,7 @@ class Move(Workflow, ModelSQL, ModelView):
|
||||
def state_date_clause(stock_assign):
|
||||
return (move.state.in_(['done',
|
||||
'assigned' if stock_assign else 'done'])
|
||||
& (
|
||||
(Coalesce(move.effective_date, move.planned_date)
|
||||
<= context['stock_date_end'])
|
||||
| (move.state == (
|
||||
'assigned'
|
||||
if not context.get('stock_date_start')
|
||||
else ''))
|
||||
))
|
||||
& (move_date <= context['stock_date_end']))
|
||||
state_date_clause_in = state_date_clause(False)
|
||||
state_date_clause_out = state_date_clause(
|
||||
context.get('stock_assign'))
|
||||
@@ -1434,39 +1435,12 @@ class Move(Workflow, ModelSQL, ModelView):
|
||||
def state_date_clause(stock_assign):
|
||||
return ((move.state.in_(['done',
|
||||
'assigned' if stock_assign else 'done'])
|
||||
& (
|
||||
(Coalesce(
|
||||
move.effective_date,
|
||||
move.planned_date,
|
||||
datetime.date.max)
|
||||
<= today)
|
||||
| (move.state == (
|
||||
'assigned'
|
||||
if not context.get('stock_date_start')
|
||||
else ''))
|
||||
)
|
||||
)
|
||||
& (move_date <= today))
|
||||
| (move.state.in_(['done', 'assigned', 'draft'])
|
||||
& (
|
||||
(
|
||||
(Coalesce(
|
||||
move.effective_date,
|
||||
move.planned_date,
|
||||
datetime.date.max)
|
||||
<= context['stock_date_end'])
|
||||
& (Coalesce(
|
||||
move.effective_date,
|
||||
move.planned_date,
|
||||
datetime.date.max)
|
||||
>= today)
|
||||
)
|
||||
| (move.state == (
|
||||
'assigned'
|
||||
if not context.get('stock_date_start')
|
||||
else ''))
|
||||
)
|
||||
)
|
||||
)
|
||||
& (Coalesce(move_date, datetime.date.max)
|
||||
<= context['stock_date_end'])
|
||||
& (Coalesce(move_date, datetime.date.max) >= today)
|
||||
))
|
||||
state_date_clause_in = state_date_clause(False)
|
||||
state_date_clause_out = state_date_clause(
|
||||
context.get('stock_assign'))
|
||||
@@ -1475,10 +1449,7 @@ class Move(Workflow, ModelSQL, ModelView):
|
||||
if context['stock_date_start'] > today:
|
||||
def state_date_clause():
|
||||
return (move.state.in_(['done', 'assigned', 'draft'])
|
||||
& (Coalesce(
|
||||
move.effective_date,
|
||||
move.planned_date,
|
||||
datetime.date.max)
|
||||
& (Coalesce(move_date, datetime.date.max)
|
||||
>= context['stock_date_start'])
|
||||
)
|
||||
state_date_clause_in &= state_date_clause()
|
||||
@@ -1487,23 +1458,14 @@ class Move(Workflow, ModelSQL, ModelView):
|
||||
def state_date_clause(stock_assign):
|
||||
return ((
|
||||
move.state.in_(['done', 'assigned', 'draft'])
|
||||
& (Coalesce(
|
||||
move.effective_date,
|
||||
move.planned_date,
|
||||
datetime.date.max) >= today)
|
||||
& (Coalesce(move_date, datetime.date.max) >= today)
|
||||
)
|
||||
| (
|
||||
move.state.in_(['done',
|
||||
'assigned' if stock_assign else 'done'])
|
||||
& (Coalesce(
|
||||
move.effective_date,
|
||||
move.planned_date,
|
||||
datetime.date.max)
|
||||
& (Coalesce(move_date, datetime.date.max)
|
||||
>= context['stock_date_start'])
|
||||
& (Coalesce(
|
||||
move.effective_date,
|
||||
move.planned_date,
|
||||
datetime.date.min) < today)
|
||||
& (Coalesce(move_date, datetime.date.min) < today)
|
||||
)
|
||||
)
|
||||
state_date_clause_in &= state_date_clause(False)
|
||||
@@ -1519,8 +1481,8 @@ class Move(Workflow, ModelSQL, ModelView):
|
||||
period, = periods
|
||||
|
||||
def state_date_clause():
|
||||
return (Coalesce(move.effective_date, move.planned_date,
|
||||
datetime.date.max) > period.date)
|
||||
return (
|
||||
Coalesce(move_date, datetime.date.max) > period.date)
|
||||
state_date_clause_in &= state_date_clause()
|
||||
state_date_clause_out &= state_date_clause()
|
||||
|
||||
|
||||
@@ -1431,13 +1431,37 @@ class StockTestCase(
|
||||
[storage.id], grouping_filter=([product.id],))
|
||||
self.assertDictEqual(pbl, {(storage.id, product.id): 5})
|
||||
|
||||
with Transaction().set_context(
|
||||
stock_date_start=today - relativedelta(days=1),
|
||||
stock_date_end=today - relativedelta(days=1),
|
||||
stock_assign=True):
|
||||
pbl = Product.products_by_location(
|
||||
[storage.id], grouping_filter=([product.id],))
|
||||
self.assertDictEqual(pbl, {})
|
||||
|
||||
with Transaction().set_context(
|
||||
stock_date_start=today - relativedelta(days=1),
|
||||
stock_date_end=today,
|
||||
stock_assign=True):
|
||||
pbl = Product.products_by_location(
|
||||
[storage.id], grouping_filter=([product.id],))
|
||||
self.assertDictEqual(pbl, {(storage.id, product.id): 5})
|
||||
|
||||
with Transaction().set_context(
|
||||
stock_date_start=today,
|
||||
stock_date_end=today,
|
||||
stock_assign=True):
|
||||
pbl = Product.products_by_location(
|
||||
[storage.id], grouping_filter=([product.id],))
|
||||
self.assertDictEqual(pbl, {(storage.id, product.id): 10})
|
||||
self.assertDictEqual(pbl, {(storage.id, product.id): 5})
|
||||
|
||||
with Transaction().set_context(
|
||||
stock_date_start=today,
|
||||
stock_date_end=today + relativedelta(days=1),
|
||||
stock_assign=True):
|
||||
pbl = Product.products_by_location(
|
||||
[storage.id], grouping_filter=([product.id],))
|
||||
self.assertDictEqual(pbl, {(storage.id, product.id): 5})
|
||||
|
||||
with Transaction().set_context(
|
||||
stock_date_start=today + relativedelta(days=1),
|
||||
@@ -1445,7 +1469,7 @@ class StockTestCase(
|
||||
stock_assign=True):
|
||||
pbl = Product.products_by_location(
|
||||
[storage.id], grouping_filter=([product.id],))
|
||||
self.assertDictEqual(pbl, {(storage.id, product.id): -5})
|
||||
self.assertDictEqual(pbl, {})
|
||||
|
||||
@with_transaction()
|
||||
def test_location_inactive_without_move(self):
|
||||
|
||||
Reference in new issue
Block a user