Can't read product in Product by Location and those products was created after forecast date
Install stock and product_cost_history modules:
Scenario:
1- Create some products
2- Create some shipments. Date 2018-01-01
3- Create new products
4- Create some new shipments. Date 2018-03-31
5- Go to Locations. Product by Locations. Select forecast date: 2018-01-01
Get error: "You try to read records that don't exist anymore.\n(Document type: product.product)" because read() in modelsql, some products do not have cost price before 2018-03-31 (history rows are not equal sub_ids [1]).
The query is [2]
('SELECT "a"."id" FROM "product_product__history" AS "a" WHERE ((("a"."id" IN (%s))) AND (COALESCE("a"."write_date", "a"."create_date") <= %s))
ORDER BY COALESCE("a"."write_date", "a"."create_date") DESC, "a"."__id" DESC LIMIT 1', (142495, datetime.datetime(2018, 3, 31, 23, 59, 59, 999999)))
In this case, product ID 142495 was created 2018-03-31 and when get products by location there are not cost price in 2018-01-01
[1] https://bitbucket.org/tryton/trytond/src/43f7277b81a28cd8b94d4e63c510b69ec6a815c8/trytond/model/modelsql.py?at=default&fileviewer=file-view-default#modelsql.py-747
[2] https://bitbucket.org/tryton/trytond/src/43f7277b81a28cd8b94d4e63c510b69ec6a815c8/trytond/model/modelsql.py?at=default&fileviewer=file-view-default#modelsql.py-744