diff --git a/CHANGELOG b/CHANGELOG index a7690655c8..52fa1480de 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add today record in Product Quantities By Warehouse * Allow consumable product on inventories * Let the user select a default warehouse * Add method to get default warehouse diff --git a/product.py b/product.py index 2afb9261cc..51f204418c 100644 --- a/product.py +++ b/product.py @@ -5,7 +5,7 @@ import functools from decimal import Decimal from collections import defaultdict -from sql import Literal, Null +from sql import Literal, Null, Select from sql.aggregate import Max from sql.functions import CurrentTimestamp from sql.conditionals import Coalesce @@ -348,8 +348,10 @@ class ProductQuantitiesByWarehouse(ModelSQL, ModelView): Move = pool.get('stock.move') Location = pool.get('stock.location') Product = pool.get('product.product') + Date = pool.get('ir.date') move = from_ = Move.__table__() context = Transaction().context + today = Date.today() if context.get('product_template') is not None: product = Product.__table__() @@ -363,20 +365,28 @@ class ProductQuantitiesByWarehouse(ModelSQL, ModelView): warehouse_query = Location.search([ ('parent', 'child_of', [warehouse_id]), ], query=True, order=[]) - date_column = Coalesce(move.effective_date, move.planned_date - ).as_('date') - return from_.select( - Max(move.id).as_('id'), - Literal(0).as_('create_uid'), - CurrentTimestamp().as_('create_date'), - Literal(None).as_('write_uid'), - Literal(None).as_('write_date'), - date_column, - where=product_clause - & (move.from_location.in_(warehouse_query) - | move.to_location.in_(warehouse_query)) - & (Coalesce(move.effective_date, move.planned_date) != Null), - group_by=(date_column, move.product)) + date_column = Coalesce(move.effective_date, move.planned_date) + return (from_.select( + Max(move.id).as_('id'), + Literal(0).as_('create_uid'), + CurrentTimestamp().as_('create_date'), + Literal(None).as_('write_uid'), + Literal(None).as_('write_date'), + date_column.as_('date'), + where=product_clause + & (move.from_location.in_(warehouse_query) + | move.to_location.in_(warehouse_query)) + & (Coalesce(move.effective_date, move.planned_date) != Null) + & (date_column != today), + group_by=(date_column, move.product)) + | Select([ + Literal(0).as_('id'), + Literal(0).as_('create_uid'), + CurrentTimestamp().as_('create_date'), + Literal(None).as_('write_uid'), + Literal(None).as_('write_date'), + Literal(today).as_('date'), + ])) @classmethod def get_quantity(cls, lines, name): diff --git a/tests/scenario_stock_product_quantities_by_warehouse.rst b/tests/scenario_stock_product_quantities_by_warehouse.rst index 423d911bc8..daa5ba039b 100644 --- a/tests/scenario_stock_product_quantities_by_warehouse.rst +++ b/tests/scenario_stock_product_quantities_by_warehouse.rst @@ -77,6 +77,7 @@ Check Product Quantities by Warehouse:: ... product_template=template.id, warehouse=warehouse_loc.id): ... records = ProductQuantitiesByWarehouse.find([]) >>> len(records) - 2 - >>> [(r.date, r.quantity) for r in records] == [(yesterday, 10), (tomorrow, 6)] + 3 + >>> [(r.date, r.quantity) for r in records] == [ + ... (yesterday, 10), (today, 10), (tomorrow, 6)] True