Add Product Quantities By Warehouse
review423001
This commit is contained in:
1 parent
68c4222a67
commit
5c89c26823
3 files changed
+192
No files matched your search
@@ -1,3 +1,5 @@
|
||||
* Add Product Quantities By Warehouse
|
||||
|
||||
Version 2.4.0 - 2012-04-24
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
* Remove special to_location_warehouse search clause
|
||||
|
||||
+109
@@ -615,3 +615,112 @@ class ProductByLocation(Wizard):
|
||||
return action, {}
|
||||
|
||||
ProductByLocation()
|
||||
|
||||
|
||||
class ProductQuantitiesByWarehouse(ModelSQL, ModelView):
|
||||
'Product Quantities By Warehouse'
|
||||
_name = 'stock.product_quantities_warehouse'
|
||||
_description = __doc__
|
||||
|
||||
date = fields.Date('Date')
|
||||
quantity = fields.Function(fields.Float('Quantity'), 'get_quantity')
|
||||
|
||||
def __init__(self):
|
||||
super(ProductQuantitiesByWarehouse, self).__init__()
|
||||
self._order.insert(0, ('date', 'ASC'))
|
||||
|
||||
def table_query(self):
|
||||
move_obj = Pool().get('stock.move')
|
||||
location_obj = Pool().get('stock.location')
|
||||
|
||||
product_id = Transaction().context.get('product')
|
||||
warehouse_id = Transaction().context.get('warehouse', -1)
|
||||
warehouse_clause, warehouse_params = location_obj.search([
|
||||
('parent', 'child_of', [warehouse_id]),
|
||||
], query_string=True, order=[])
|
||||
return ('SELECT MAX(id) AS id, '
|
||||
'0 AS create_uid, '
|
||||
'NOW() AS create_date, '
|
||||
'NULL AS write_uid, '
|
||||
'NULL AS write_date, '
|
||||
'COALESCE(effective_date, planned_date) AS date '
|
||||
'FROM "' + move_obj._table + '" '
|
||||
'WHERE product = %s '
|
||||
'AND (from_location IN (' + warehouse_clause + ') '
|
||||
'OR to_location IN (' + warehouse_clause + ')) '
|
||||
'AND COALESCE(effective_date, planned_date) IS NOT NULL '
|
||||
'GROUP BY date, product', [product_id] + 2 * warehouse_params)
|
||||
|
||||
def get_quantity(self, ids, name):
|
||||
product_obj = Pool().get('product.product')
|
||||
|
||||
product_id = Transaction().context.get('product')
|
||||
warehouse_id = Transaction().context.get('warehouse')
|
||||
|
||||
lines = self.browse(ids)
|
||||
dates = sorted(l.date for l in lines)
|
||||
quantities = {}
|
||||
date_start = None
|
||||
for date in dates:
|
||||
context = {
|
||||
'stock_date_start': date_start,
|
||||
'stock_date_end': date,
|
||||
}
|
||||
with Transaction().set_context(**context):
|
||||
quantities[date] = product_obj.products_by_location(
|
||||
[warehouse_id], [product_id], with_childs=True,
|
||||
skip_zero=False)[(warehouse_id, product_id)]
|
||||
date_start = date + datetime.timedelta(1)
|
||||
cumulate = 0
|
||||
for date in dates:
|
||||
cumulate += quantities[date]
|
||||
quantities[date] = cumulate
|
||||
|
||||
return dict((l.id, quantities[l.date]) for l in lines)
|
||||
|
||||
ProductQuantitiesByWarehouse()
|
||||
|
||||
|
||||
class ProductQuantitiesByWarehouseStart(ModelView):
|
||||
'Product Quantities By Warehouse'
|
||||
_name = 'stock.product_quantities_warehouse.start'
|
||||
_description = __doc__
|
||||
|
||||
warehouse = fields.Many2One('stock.location', 'Warehouse', domain=[
|
||||
('type', '=', 'warehouse'),
|
||||
])
|
||||
|
||||
def default_warehouse(self):
|
||||
location_obj = Pool().get('stock.location')
|
||||
warehouse_ids = location_obj.search([
|
||||
('type', '=', 'warehouse'),
|
||||
])
|
||||
if len(warehouse_ids) == 1:
|
||||
return warehouse_ids[0]
|
||||
|
||||
ProductQuantitiesByWarehouseStart()
|
||||
|
||||
|
||||
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, session, action):
|
||||
date_obj = Pool().get('ir.date')
|
||||
action['pyson_context'] = PYSONEncoder().encode({
|
||||
'product': Transaction().context['active_id'],
|
||||
'warehouse': session.start.warehouse.id,
|
||||
})
|
||||
action['pyson_search_value'] = PYSONEncoder().encode([
|
||||
('date', '>=', date_obj.today()),
|
||||
])
|
||||
return action, {}
|
||||
|
||||
OpenProductQuantitiesByWarehouse()
|
||||
+81
@@ -83,5 +83,86 @@ this repository contains the full copyright notices and license terms. -->
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="product_quantities_warehouse_view_graph">
|
||||
<field name="model">stock.product_quantities_warehouse</field>
|
||||
<field name="type">graph</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<graph string="Product Quantities By Warehouse" type="line"
|
||||
legend="0">
|
||||
<x>
|
||||
<field name="date"/>
|
||||
</x>
|
||||
<y>
|
||||
<field name="quantity" empty="0" interpolation="constant-left" fill="1"/>
|
||||
</y>
|
||||
</graph>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="product_quantities_warehouse_view_list">
|
||||
<field name="model">stock.product_quantities_warehouse</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<tree string="Product Quantities By Warehouse">
|
||||
<field name="date"/>
|
||||
<field name="quantity"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window"
|
||||
id="act_product_quantities_warehouse">
|
||||
<field name="name">Product Quantities By Warehouse</field>
|
||||
<field name="res_model">stock.product_quantities_warehouse</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_product_quantities_warehouse_graph_view">
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="view" ref="product_quantities_warehouse_view_graph"/>
|
||||
<field name="act_window" ref="act_product_quantities_warehouse"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_product_quantities_warehouse_list_view">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="view" ref="product_quantities_warehouse_view_list"/>
|
||||
<field name="act_window" ref="act_product_quantities_warehouse"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="product_quantities_warehouse_start_view_form">
|
||||
<field
|
||||
name="model">stock.product_quantities_warehouse.start</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Product Quantities By Warehouse">
|
||||
<label name="warehouse"/>
|
||||
<field name="warehouse"/>
|
||||
</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"/>
|
||||
</record>
|
||||
<record model="ir.action-res.group"
|
||||
id="wizard_product_quantities_warehouse-group_stock">
|
||||
<field name="action" ref="wizard_product_quantities_warehouse"/>
|
||||
<field name="group" ref="group_stock"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
||||
Reference in new issue
Block a user