diff --git a/__init__.py b/__init__.py
index bf76a9069e..2ddfc12791 100644
--- a/__init__.py
+++ b/__init__.py
@@ -15,7 +15,7 @@ def register():
Pool.register(
Location,
Party,
- ProductsByLocationsStart,
+ ProductsByLocationsContext,
Move,
ShipmentIn,
ShipmentInReturn,
@@ -30,20 +30,17 @@ def register():
Cache,
Template,
Product,
- ProductByLocationStart,
+ ProductByLocationContext,
ProductQuantitiesByWarehouse,
- ProductQuantitiesByWarehouseStart,
+ ProductQuantitiesByWarehouseContext,
Inventory,
InventoryLine,
Configuration,
module='stock', type_='model')
Pool.register(
- ProductsByLocations,
AssignShipmentOut,
AssignShipmentInternal,
AssignShipmentInReturn,
- ProductByLocation,
- OpenProductQuantitiesByWarehouse,
RecomputeCostPrice,
module='stock', type_='wizard')
Pool.register(
diff --git a/location.py b/location.py
index 75e86c72b6..b1fb04e464 100644
--- a/location.py
+++ b/location.py
@@ -3,15 +3,13 @@
import datetime
from decimal import Decimal
from trytond.model import ModelView, ModelSQL, fields
-from trytond.wizard import Wizard, StateView, Button, StateAction
from trytond import backend
-from trytond.pyson import Eval, PYSONEncoder, Date, If
+from trytond.pyson import Eval, If
from trytond.transaction import Transaction
from trytond.pool import Pool, PoolMeta
from trytond.tools import grouped_slice
-__all__ = ['Location', 'Party', 'ProductsByLocationsStart',
- 'ProductsByLocations']
+__all__ = ['Location', 'Party', 'ProductsByLocationsContext']
STATES = {
'readonly': ~Eval('active'),
@@ -406,53 +404,24 @@ class Party:
'party.'))
-class ProductsByLocationsStart(ModelView):
+class ProductsByLocationsContext(ModelView):
'Products by Locations'
- __name__ = 'stock.products_by_locations.start'
+ __name__ = 'stock.products_by_locations.context'
forecast_date = fields.Date(
'At Date', help=('Allow to compute expected '
'stock quantities for this date.\n'
'* An empty value is an infinite date in the future.\n'
'* A date in the past will provide historical values.'))
+ stock_date_end = fields.Function(fields.Date('At Date'),
+ 'on_change_with_stock_date_end')
@staticmethod
def default_forecast_date():
Date_ = Pool().get('ir.date')
return Date_.today()
-
-class ProductsByLocations(Wizard):
- 'Products by Locations'
- __name__ = 'stock.products_by_locations'
- start = StateView('stock.products_by_locations.start',
- 'stock.products_by_locations_start_view_form', [
- Button('Cancel', 'end', 'tryton-cancel'),
- Button('Open', 'open', 'tryton-ok', True),
- ])
- open = StateAction('stock.act_products_by_locations')
-
- def do_open(self, action):
- pool = Pool()
- Location = pool.get('stock.location')
- Lang = pool.get('ir.lang')
-
- context = {}
- context['locations'] = Transaction().context.get('active_ids')
- date = self.start.forecast_date or datetime.date.max
- context['stock_date_end'] = Date(date.year, date.month, date.day)
- action['pyson_context'] = PYSONEncoder().encode(context)
-
- locations = Location.browse(context['locations'])
-
- for code in [Transaction().language, 'en_US']:
- langs = Lang.search([
- ('code', '=', code),
- ])
- if langs:
- break
- lang = langs[0]
- date = Lang.strftime(date, lang.code, lang.date)
-
- action['name'] += ' - (%s) @ %s' % (
- ','.join(l.name for l in locations), date)
- return action, {}
+ @fields.depends('forecast_date')
+ def on_change_with_stock_date_end(self, name=None):
+ if self.forecast_date is None:
+ return datetime.datetime.max
+ return self.forecast_date
diff --git a/location.xml b/location.xml
index b732bd8c49..e2a597afab 100644
--- a/location.xml
+++ b/location.xml
@@ -57,12 +57,23 @@ this repository contains the full copyright notices and license terms. -->
+
+ stock.products_by_locations.context
+ form
+ products_by_locations_context_form
+
+
Products
product.product
+
+ stock.products_by_locations.context
@@ -74,23 +85,17 @@ this repository contains the full copyright notices and license terms. -->
-
-
- Products by Locations
- stock.products_by_locations
- stock.location
-
tree_open
stock.location,-1
-
+
form_relate
stock.location,-1
-
+
@@ -115,11 +120,6 @@ this repository contains the full copyright notices and license terms. -->
party_form
-
- stock.products_by_locations.start
- form
- products_by_locations_start_form
-
diff --git a/product.py b/product.py
index 047af080fd..3db784c422 100644
--- a/product.py
+++ b/product.py
@@ -10,9 +10,8 @@ from sql.functions import CurrentTimestamp
from sql.conditionals import Coalesce
from trytond.model import ModelSQL, ModelView, fields
-from trytond.wizard import Wizard, StateView, StateAction, StateTransition, \
- Button
-from trytond.pyson import PYSONEncoder, Eval, Or
+from trytond.wizard import Wizard, StateTransition
+from trytond.pyson import Eval, Or
from trytond.transaction import Transaction
from trytond.pool import Pool, PoolMeta
from trytond.tools import grouped_slice
@@ -20,9 +19,8 @@ from trytond.tools import grouped_slice
from .move import StockMixin
__all__ = ['Template', 'Product',
- 'ProductByLocationStart', 'ProductByLocation',
- 'ProductQuantitiesByWarehouse', 'ProductQuantitiesByWarehouseStart',
- 'OpenProductQuantitiesByWarehouse',
+ 'ProductByLocationContext',
+ 'ProductQuantitiesByWarehouse', 'ProductQuantitiesByWarehouseContext',
'RecomputeCostPrice']
@@ -274,59 +272,27 @@ class Product(StockMixin, object):
return cost_price
-class ProductByLocationStart(ModelView):
+class ProductByLocationContext(ModelView):
'Product by Location'
- __name__ = 'product.by_location.start'
+ __name__ = 'product.by_location.context'
forecast_date = fields.Date(
'At Date', help=('Allow to compute expected '
'stock quantities for this date.\n'
'* An empty value is an infinite date in the future.\n'
'* A date in the past will provide historical values.'))
+ stock_date_end = fields.Function(fields.Date('At Date'),
+ 'on_change_with_stock_date_end')
@staticmethod
def default_forecast_date():
Date = Pool().get('ir.date')
return Date.today()
-
-class ProductByLocation(Wizard):
- 'Product by Location'
- __name__ = 'product.by_location'
- start = StateView('product.by_location.start',
- 'stock.product_by_location_start_view_form', [
- Button('Cancel', 'end', 'tryton-cancel'),
- Button('Open', 'open', 'tryton-ok', default=True),
- ])
- open = StateAction('stock.act_location_quantity_tree')
-
- def do_open(self, action):
- pool = Pool()
- Product = pool.get('product.product')
- Lang = pool.get('ir.lang')
-
- context = {}
- product_id = Transaction().context['active_id']
- context['product'] = product_id
- if self.start.forecast_date:
- context['stock_date_end'] = self.start.forecast_date
- else:
- context['stock_date_end'] = datetime.date.max
- action['pyson_context'] = PYSONEncoder().encode(context)
- product = Product(product_id)
-
- for code in [Transaction().language, 'en_US']:
- langs = Lang.search([
- ('code', '=', code),
- ])
- if langs:
- break
- lang, = langs
- date = Lang.strftime(context['stock_date_end'],
- lang.code, lang.date)
-
- action['name'] += ' - %s (%s) @ %s' % (product.rec_name,
- product.default_uom.rec_name, date)
- return action, {}
+ @fields.depends('forecast_date')
+ def on_change_with_stock_date_end(self, name=None):
+ if self.forecast_date is None:
+ return datetime.datetime.max
+ return self.forecast_date
class ProductQuantitiesByWarehouse(ModelSQL, ModelView):
@@ -399,9 +365,9 @@ class ProductQuantitiesByWarehouse(ModelSQL, ModelView):
return dict((l.id, quantities[l.date]) for l in lines)
-class ProductQuantitiesByWarehouseStart(ModelView):
+class ProductQuantitiesByWarehouseContext(ModelView):
'Product Quantities By Warehouse'
- __name__ = 'stock.product_quantities_warehouse.start'
+ __name__ = 'stock.product_quantities_warehouse.context'
warehouse = fields.Many2One('stock.location', 'Warehouse', required=True,
domain=[
('type', '=', 'warehouse'),
@@ -417,28 +383,6 @@ class ProductQuantitiesByWarehouseStart(ModelView):
return warehouses[0].id
-class OpenProductQuantitiesByWarehouse(Wizard):
- 'Product Quantities By Warehouse'
- __name__ = 'stock.product_quantities_warehouse'
- start = StateView('stock.product_quantities_warehouse.start',
- 'stock.product_quantities_warehouse_start_view_form', [
- Button('Cancel', 'end', 'tryton-cancel'),
- Button('Open', 'open_', 'tryton-ok', default=True),
- ])
- open_ = StateAction('stock.act_product_quantities_warehouse')
-
- def do_open_(self, action):
- Date = Pool().get('ir.date')
- action['pyson_context'] = PYSONEncoder().encode({
- 'product': Transaction().context['active_id'],
- 'warehouse': self.start.warehouse.id,
- })
- action['pyson_search_value'] = PYSONEncoder().encode([
- ('date', '>=', Date.today()),
- ])
- return action, {}
-
-
class RecomputeCostPrice(Wizard):
'Recompute Cost Price'
__name__ = 'product.recompute_cost_price'
diff --git a/product.xml b/product.xml
index 9547214785..7cb7e492c9 100644
--- a/product.xml
+++ b/product.xml
@@ -41,36 +41,34 @@ this repository contains the full copyright notices and license terms. -->
- Locations
+ Locations Quantity
stock.location
+
+ product.by_location.context
-
- Product by Locations
- product.by_location
- product.product
-
form_relate
product.product,-1
-
+
-
+ id="act_location-quantity_tree-group_stock">
+
-
- product.by_location.start
+
+ product.by_location.context
form
- product_by_location_start_form
+ product_by_location_context_form
@@ -89,6 +87,11 @@ this repository contains the full copyright notices and license terms. -->
id="act_product_quantities_warehouse">
Product Quantities By Warehouse
stock.product_quantities_warehouse
+
+
+ stock.product_quantities_warehouse.context
@@ -103,28 +106,22 @@ this repository contains the full copyright notices and license terms. -->
-
+
stock.product_quantities_warehouse.start
+ name="model">stock.product_quantities_warehouse.context
form
- product_quantities_warehouse_start_form
+ product_quantities_warehouse_context_form
-
- Product Quantities By Warehouse
- stock.product_quantities_warehouse
- product.product
-
form_relate
product.product,-1
-
+
-
+ id="act_product_quantities_warehouse-group_stock">
+
diff --git a/view/product_by_location_start_form.xml b/view/product_by_location_context_form.xml
similarity index 82%
rename from view/product_by_location_start_form.xml
rename to view/product_by_location_context_form.xml
index 6d15c30a2f..9000184061 100644
--- a/view/product_by_location_start_form.xml
+++ b/view/product_by_location_context_form.xml
@@ -4,4 +4,5 @@ this repository contains the full copyright notices and license terms. -->
diff --git a/view/product_quantities_warehouse_start_form.xml b/view/product_quantities_warehouse_context_form.xml
similarity index 100%
rename from view/product_quantities_warehouse_start_form.xml
rename to view/product_quantities_warehouse_context_form.xml
diff --git a/view/products_by_locations_start_form.xml b/view/products_by_locations_context_form.xml
similarity index 71%
rename from view/products_by_locations_start_form.xml
rename to view/products_by_locations_context_form.xml
index 7bc1757728..9000184061 100644
--- a/view/products_by_locations_start_form.xml
+++ b/view/products_by_locations_context_form.xml
@@ -1,7 +1,8 @@
-