diff --git a/addons/account/report/__init__.py b/addons/account/report/__init__.py
index 482b9b62280..ad965e04b57 100644
--- a/addons/account/report/__init__.py
+++ b/addons/account/report/__init__.py
@@ -30,7 +30,7 @@ import invoice
import overdue
import aged_trial_balance
import tax_report
-import account_tax_code
+#import account_tax_code
import account_balance_landscape
import compare_account_balance
import account_invoice_report
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 87346d092f6..1b8e3de26e5 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -1689,15 +1689,25 @@ class stock_move(osv.osv):
new_move = []
update_val = {}
ir_sequence_obj = self.pool.get('ir.sequence')
- prodlot_obj = self.pool.get('stock.production.lot')
- last_prod = [line.prodlot_id for line in self.browse(cr, uid, ids)[0].picking_id.move_lines if line.prodlot_id]
- last_prod.sort(key=lambda p: p.date, reverse=True)
- last_prod_id = last_prod and last_prod[0].id
- update_val['prodlot_id'] = last_prod_id
- if update_val.get('prodlot_id',[])==[]:
- sequence = ir_sequence_obj.get(cr, uid, 'stock.lot.serial')
- prodlot_id = prodlot_obj.create(cr, uid, {'name': sequence}, {'product_id': self.browse(cr, uid, ids)[0].product_id.id})
- update_val['prodlot_id'] = prodlot_id
+ tracking_obj = self.pool.get('stock.tracking')
+ tracking = False
+ tracking = context.get('tracking', False)
+ # import pdb; pdb.set_trace()
+ if tracking:
+ tracking_id = tracking_obj.search(cr, uid, ['name','=', tracking])
+ if prodlot_id:
+ update_val['prodlot_id'] = prodlot_id
+ else:
+ tracking_id = tracking_obj.create(cr, uid, {'name': tracking}, {'product_id': self.browse(cr, uid, ids)[0].product_id.id})
+ update_val['tracking_id'] = tracking_id
+ else:
+ last_track = [line.tracking_id for line in self.browse(cr, uid, ids)[0].picking_id.move_lines if line.tracking_id]
+ if not last_track:
+ track_ids= tracking_obj.search(cr, uid, [])
+ last_track = [track for track in tracking_obj.browse(cr, uid, track_ids)]
+ last_track.sort(key=lambda p: p.date, reverse=True)
+ last_track_id = last_track and last_track[0].id
+ update_val['tracking_id'] = last_track_id
self.write(cr, uid, ids, update_val)
return True
diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml
index 3171387aaa6..ab33b07aacb 100644
--- a/addons/stock/stock_view.xml
+++ b/addons/stock/stock_view.xml
@@ -1630,6 +1630,10 @@
+
+
+
+
diff --git a/addons/stock_avg_consommation/__init__.py b/addons/stock_avg_consommation/__init__.py
new file mode 100644
index 00000000000..c4d17a90d9a
--- /dev/null
+++ b/addons/stock_avg_consommation/__init__.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+import stock_avg_consommation
+import wizard
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/stock_avg_consommation/__openerp__.py b/addons/stock_avg_consommation/__openerp__.py
new file mode 100644
index 00000000000..37008770cae
--- /dev/null
+++ b/addons/stock_avg_consommation/__openerp__.py
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+
+{
+ 'name': 'Stock Average consommation',
+ 'version': '1.0',
+ 'category': 'Generic Modules/Inventory Control',
+ 'author': 'Tiny',
+ 'depends': ['stock'],
+ 'init_xml': [],
+ 'update_xml': ['stock_avg_consommation_view.xml'],
+ 'demo_xml': [],
+ 'installable': True,
+ 'active': False,
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/stock_avg_consommation/stock_avg_consommation.py b/addons/stock_avg_consommation/stock_avg_consommation.py
new file mode 100644
index 00000000000..b9dab63d18b
--- /dev/null
+++ b/addons/stock_avg_consommation/stock_avg_consommation.py
@@ -0,0 +1,100 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+from osv import fields,osv
+import tools
+import ir
+import pooler
+from mx import DateTime
+from datetime import datetime
+import time
+from dateutil.relativedelta import relativedelta
+
+class stock_avg_consommation(osv.osv):
+ _name = "stock.avg.consommation"
+ _inherit="product.product"
+
+ def _compute_avg_consommation(self, cr, uid, ids, fields, args, context={}):
+ print ids, fields, args, context
+ date_str=False
+ from_date=context.get('from_date',False)
+ to_date=context.get('to_date',False)
+
+ if from_date and to_date:
+ date_str="date_planned>='%s' and date_planned<='%s'"%(from_date,to_date)
+ elif from_date:
+ date_str="date_planned>='%s'"%(from_date)
+ elif to_date:
+ date_str="date_planned<='%s'"%(to_date)
+
+ date_object_to = to_date and datetime.strptime(to_date, '%Y-%m-%d %H:%M:%S') or datetime.now()
+ date_object_from = from_date and datetime.strptime(from_date, '%Y-%m-%d %H:%M:%S') or (datetime.now() + relativedelta(days=-30))
+ dd = date_object_to - date_object_from
+ total_days=dd.days+1
+ if not from_date and not to_date:
+ date_str="date_planned>='%s' and date_planned<='%s'"%(date_object_from.strftime('%Y-%m-%d 00:00:00'), date_object_to.strftime('%Y-%m-%d 23:59:59'))
+ elif not from_date:
+ date_str="date_planned>='%s'"%(date_object_from.strftime('%Y-%m-%d 00:00:00'))
+ elif not to_date:
+ date_str="date_planned<='%s'"%(date_object_to.strftime('%Y-%m-%d 23:59:59'))
+ res={}
+ for line_id in ids:
+ res[line_id] = False
+ location_ids = []
+
+ if context.get('location', False):
+ if type(context['location']) == type(1):
+ location_ids = [context['location']]
+ elif type(context['location']) in (type(''), type(u'')):
+ location_ids = self.pool.get('stock.location').search(cr, uid, [('name','ilike',context['location'])], context=context)
+ else:
+ location_ids = context['location']
+ else:
+ location_ids = []
+ wids = self.pool.get('stock.warehouse').search(cr, uid, [], context=context)
+ for w in self.pool.get('stock.warehouse').browse(cr, uid, wids, context=context):
+ location_ids.append(w.lot_stock_id.id)
+
+ # build the list of ids of children of the location given by id
+ if context.get('compute_child',True):
+ child_location_ids = self.pool.get('stock.location').search(cr, uid, [('location_id', 'child_of', location_ids)])
+ location_ids = child_location_ids or location_ids
+ else:
+ location_ids = location_ids
+
+
+
+ #sql = """select product_id,sum(product_qty) from stock_move sm,stock_picking sp where sm.picking_id=sp.id and sp.type in ('out','delivery') and %s and location_id <> ANY(%s) and location_dest_id =ANY(%s) group by product_id""" % (date_str, location_ids, location_ids)
+ sql = """select product_id,sum(product_qty) from stock_move sm,stock_picking sp where sm.picking_id=sp.id and sp.type in ('out','delivery') and """+date_str+""" and sm.location_id not in %s and sm.location_dest_id in %s group by product_id"""
+ cr.execute(sql, [tuple(location_ids), tuple(location_ids)])
+ product_ids = []
+ res_sum = cr.fetchall()
+ for line_id, avg in res_sum:
+ res[line_id] = avg/total_days
+ product_ids.append(avg)
+ return res
+
+ _columns = {
+ 'avg_consommation':fields.function(_compute_avg_consommation,method=True, type='float', string="Average Consommation"),
+ }
+stock_avg_consommation()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/stock_avg_consommation/stock_avg_consommation_view.xml b/addons/stock_avg_consommation/stock_avg_consommation_view.xml
new file mode 100644
index 00000000000..d9afed69af3
--- /dev/null
+++ b/addons/stock_avg_consommation/stock_avg_consommation_view.xml
@@ -0,0 +1,18 @@
+
+
+
+
+ stock.avg.consommation.tree
+ stock.avg.consommation
+ tree
+
+
+
+
+
+
+
+
+
+
+
diff --git a/addons/stock_avg_consommation/wizard/__init__.py b/addons/stock_avg_consommation/wizard/__init__.py
new file mode 100644
index 00000000000..a7d7cfed3dc
--- /dev/null
+++ b/addons/stock_avg_consommation/wizard/__init__.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+import stock_avg_consommation_wizard
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/stock_avg_consommation/wizard/stock_avg_consommation_wizard.py b/addons/stock_avg_consommation/wizard/stock_avg_consommation_wizard.py
new file mode 100644
index 00000000000..7d5d8657aa2
--- /dev/null
+++ b/addons/stock_avg_consommation/wizard/stock_avg_consommation_wizard.py
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+from osv import fields, osv
+
+class stock_location_product(osv.osv_memory):
+ _inherit = "stock.location.product"
+
+ def action_open_window(self, cr, uid, ids, context):
+ """ To open location wise product information specific to given duration
+ @param self: The object pointer.
+ @param cr: A database cursor
+ @param uid: ID of the user currently logged in
+ @param ids: An ID or list of IDs if we want more than one
+ @param context: A standard dictionary
+ @return: Invoice type
+ """
+
+ mod_obj = self.pool.get('ir.model.data')
+ view = mod_obj._get_id(cr, uid, 'stock_avg_consommation', 'stock_avg_consommation_tree')
+ id = mod_obj.read(cr, uid, view, ['res_id'])
+
+ for location_obj in self.read(cr, uid, ids, ['from_date', 'to_date']):
+ return {
+ 'name': False,
+ 'view_id':[id['res_id']],
+ 'view_type': 'form',
+ 'view_mode': 'tree,form',
+ 'res_model': 'stock.avg.consommation',
+ 'type': 'ir.actions.act_window',
+ 'context': {'location': context['active_id'],
+ 'from_date': location_obj['from_date'],
+ 'to_date': location_obj['to_date']},
+ 'domain': [('type', '<>', 'service')],
+ }
+
+stock_location_product()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file