Use context model in quantities computation actions

issue5541
review20181002
This commit is contained in:
Sergi Almacellas Abellana committed 2016-06-15 10:45:54 +02:00
1 parent dd984f15c9
commit 7851e5aed6
8 files changed
+66 -157

No files matched your search

+3 -6
View File
@@ -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(
+11 -42
View File
@@ -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
+13 -13
View File
@@ -57,12 +57,23 @@ this repository contains the full copyright notices and license terms. -->
<menuitem parent="menu_configuration" sequence="10"
action="act_location_form" id="menu_location_form"/>
<record model="ir.ui.view"
id="products_by_locations_context_view_form">
<field
name="model">stock.products_by_locations.context</field>
<field name="type">form</field>
<field name="name">products_by_locations_context_form</field>
</record>
<record model="ir.action.act_window" id="act_products_by_locations">
<field name="name">Products</field>
<field name="res_model">product.product</field>
<field name="context" eval="{'locations': Eval('active_ids')}"
pyson="1"/>
<field name="domain"
eval="['OR', ('quantity', '!=', 0.0), ('forecast_quantity', '!=', 0.0)]"
pyson="1"/>
<field name="context_model">stock.products_by_locations.context</field>
</record>
<record model="ir.action.act_window.view" id="act_product_form_view2">
<field name="sequence" eval="10"/>
@@ -74,23 +85,17 @@ this repository contains the full copyright notices and license terms. -->
<field name="view" ref="product.product_view_form"/>
<field name="act_window" ref="act_products_by_locations"/>
</record>
<record model="ir.action.wizard" id="wizard_products_by_locations">
<field name="name">Products by Locations</field>
<field name="wiz_name">stock.products_by_locations</field>
<field name="model">stock.location</field>
</record>
<record model="ir.action.keyword"
id="act_products_by_locations_keyword1">
<field name="keyword">tree_open</field>
<field name="model">stock.location,-1</field>
<field name="action" ref="wizard_products_by_locations"/>
<field name="action" ref="act_products_by_locations"/>
</record>
<record model="ir.action.keyword"
id="act_products_by_locations_keyword2">
<field name="keyword">form_relate</field>
<field name="model">stock.location,-1</field>
<field name="action" ref="wizard_products_by_locations"/>
<field name="action" ref="act_products_by_locations"/>
</record>
<record model="ir.model.access" id="access_location">
@@ -115,11 +120,6 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">party_form</field>
</record>
<record model="ir.ui.view" id="products_by_locations_start_view_form">
<field name="model">stock.products_by_locations.start</field>
<field name="type">form</field>
<field name="name">products_by_locations_start_form</field>
</record>
</data>
<data noupdate="1">
+15 -71
View File
@@ -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'
+21 -24
View File
@@ -41,36 +41,34 @@ this repository contains the full copyright notices and license terms. -->
</record>
<record model="ir.action.act_window" id="act_location_quantity_tree">
<field name="name">Locations</field>
<field name="name">Locations Quantity</field>
<field name="res_model">stock.location</field>
<field name="domain" eval="[('parent', '=', None)]" pyson="1"/>
<field name="context" eval="{'product': Eval('active_id')}"
pyson="1"/>
<field name="context_model">product.by_location.context</field>
</record>
<record model="ir.action.act_window.view" id="act_location_quantity_tree_view">
<field name="sequence" eval="10"/>
<field name="view" ref="location_quantity_view_tree"/>
<field name="act_window" ref="act_location_quantity_tree"/>
</record>
<record model="ir.action.wizard" id="wizard_product_by_location">
<field name="name">Product by Locations</field>
<field name="wiz_name">product.by_location</field>
<field name="model">product.product</field>
</record>
<record model="ir.action.keyword"
id="act_location_quantity_keyword1">
<field name="keyword">form_relate</field>
<field name="model">product.product,-1</field>
<field name="action" ref="wizard_product_by_location"/>
<field name="action" ref="act_location_quantity_tree"/>
</record>
<record model="ir.action-res.group"
id="wizard_product_by_location-group_stock">
<field name="action" ref="wizard_product_by_location"/>
id="act_location-quantity_tree-group_stock">
<field name="action" ref="act_location_quantity_tree"/>
<field name="group" ref="group_stock"/>
</record>
<record model="ir.ui.view" id="product_by_location_start_view_form">
<field name="model">product.by_location.start</field>
<record model="ir.ui.view" id="product_by_location_context_view_form">
<field name="model">product.by_location.context</field>
<field name="type">form</field>
<field name="name">product_by_location_start_form</field>
<field name="name">product_by_location_context_form</field>
</record>
<record model="ir.ui.view" id="product_quantities_warehouse_view_graph">
@@ -89,6 +87,11 @@ this repository contains the full copyright notices and license terms. -->
id="act_product_quantities_warehouse">
<field name="name">Product Quantities By Warehouse</field>
<field name="res_model">stock.product_quantities_warehouse</field>
<field name="context" eval="{'product': Eval('active_id')}"
pyson="1"/>
<field name="search_value" eval="[('date', '>=', Date())]"
pyson="1"/>
<field name="context_model">stock.product_quantities_warehouse.context</field>
</record>
<record model="ir.action.act_window.view"
id="act_product_quantities_warehouse_graph_view">
@@ -103,28 +106,22 @@ this repository contains the full copyright notices and license terms. -->
<field name="act_window" ref="act_product_quantities_warehouse"/>
</record>
<record model="ir.ui.view" id="product_quantities_warehouse_start_view_form">
<record model="ir.ui.view" id="product_quantities_warehouse_context_view_form">
<field
name="model">stock.product_quantities_warehouse.start</field>
name="model">stock.product_quantities_warehouse.context</field>
<field name="type">form</field>
<field name="name">product_quantities_warehouse_start_form</field>
<field name="name">product_quantities_warehouse_context_form</field>
</record>
<record model="ir.action.wizard"
id="wizard_product_quantities_warehouse">
<field name="name">Product Quantities By Warehouse</field>
<field name="wiz_name">stock.product_quantities_warehouse</field>
<field name="model">product.product</field>
</record>
<record model="ir.action.keyword"
id="act_product_quantities_warehouse_keyword1">
<field name="keyword">form_relate</field>
<field name="model">product.product,-1</field>
<field name="action" ref="wizard_product_quantities_warehouse"/>
<field name="action" ref="act_product_quantities_warehouse"/>
</record>
<record model="ir.action-res.group"
id="wizard_product_quantities_warehouse-group_stock">
<field name="action" ref="wizard_product_quantities_warehouse"/>
id="act_product_quantities_warehouse-group_stock">
<field name="action" ref="act_product_quantities_warehouse"/>
<field name="group" ref="group_stock"/>
</record>
@@ -4,4 +4,5 @@ this repository contains the full copyright notices and license terms. -->
<form string="Product by Location">
<label name="forecast_date"/>
<field name="forecast_date"/>
<field name="stock_date_end" invisible="1" colspan="4"/>
</form>
@@ -1,7 +1,8 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<form string="Products by Locations">
<form string="Product by Location">
<label name="forecast_date"/>
<field name="forecast_date"/>
<field name="stock_date_end" invisible="1" colspan="4"/>
</form>