From 4c1ac43aa239f776da09318bb827679fa7e1fc07 Mon Sep 17 00:00:00 2001 From: "qdp-launchpad@tinyerp.com" <> Date: Wed, 16 Jun 2010 12:08:18 +0200 Subject: [PATCH 1/2] [FIX] stock: put back required=True on company_id field of picking and stock move [REF] stock_location: removed the chained_company_id stuff bzr revid: qdp-launchpad@tinyerp.com-20100616100818-uihigpv4fklgxbdz --- addons/stock/stock.py | 4 ++-- addons/stock_location/mrp_pull.py | 4 ++-- addons/stock_location/stock.py | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 87346d092f6..00bdb4e07e8 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -602,7 +602,7 @@ class stock_picking(osv.osv): ("2binvoiced", "To Be Invoiced"), ("none", "Not from Picking")], "Invoice Status", select=True, required=True, readonly=True, states={'draft': [('readonly', False)]}), - 'company_id': fields.many2one('res.company', 'Company', select=1), + 'company_id': fields.many2one('res.company', 'Company', required=True, select=1), } _defaults = { 'name': lambda self, cr, uid, context: '/', @@ -1380,7 +1380,7 @@ class stock_move(osv.osv): \nThe state is \'Waiting\' if the move is waiting for another one.'), 'price_unit': fields.float('Unit Price', digits_compute= dp.get_precision('Account')), - 'company_id': fields.many2one('res.company', 'Company', select=1), + 'company_id': fields.many2one('res.company', 'Company', required=True, select=1), 'partner_id': fields.related('picking_id','address_id','partner_id',type='many2one', relation="res.partner", string="Partner"), 'backorder_id': fields.related('picking_id','backorder_id',type='many2one', relation="stock.picking", string="Back Order"), 'origin': fields.related('picking_id','origin',type='char', size=64, relation="stock.picking", string="Origin"), diff --git a/addons/stock_location/mrp_pull.py b/addons/stock_location/mrp_pull.py index 4f9c22a54cd..a8a5026bf4c 100644 --- a/addons/stock_location/mrp_pull.py +++ b/addons/stock_location/mrp_pull.py @@ -68,7 +68,7 @@ class procurement_order(osv.osv): origin = (proc.origin or proc.name or '').split(':')[0] +':'+line.name picking_id = self.pool.get('stock.picking').create(cr, uid, { 'origin': origin, - 'company_id': line.chained_company_id and line.chained_company_id.id or False, + 'company_id': line.company_id and line.company_id.id or False, 'type': line.picking_type, 'stock_journal_id': line.journal_id and line.journal_id.id or False, 'move_type': 'one', @@ -79,7 +79,7 @@ class procurement_order(osv.osv): move_id = self.pool.get('stock.move').create(cr, uid, { 'name': line.name, 'picking_id': picking_id, - 'company_id': line.chained_company_id and line.chained_company_id.id or False, + 'company_id': line.company_id and line.company_id.id or False, 'product_id': proc.product_id.id, 'date_planned': proc.date_planned, 'product_qty': proc.product_qty, diff --git a/addons/stock_location/stock.py b/addons/stock_location/stock.py index d49b9ffbafa..561cdbbecda 100644 --- a/addons/stock_location/stock.py +++ b/addons/stock_location/stock.py @@ -40,7 +40,6 @@ class stock_location_path(osv.osv): ("none", "Not from Picking")], "Invoice Status", required=True,), 'picking_type': fields.selection([('out','Sending Goods'),('in','Getting Goods'),('internal','Internal'),('delivery','Delivery')], 'Shipping Type', required=True, select=True, help="Depending on the company, choose whatever you want to receive or send products"), - 'chained_company_id': fields.many2one('res.company', 'Chained Company', help='Set here the belonging company of the chained move'), 'auto': fields.selection( [('auto','Automatic Move'), ('manual','Manual Operation'),('transparent','Automatic No Step Added')], 'Automatic Move', @@ -73,7 +72,6 @@ class product_pulled_flow(osv.osv): 'company_id': fields.many2one('res.company', 'Company', help="Is used to know to which company belong packings and moves"), 'partner_address_id': fields.many2one('res.partner.address', 'Partner Address'), 'picking_type': fields.selection([('out','Sending Goods'),('in','Getting Goods'),('internal','Internal'),('delivery','Delivery')], 'Shipping Type', required=True, select=True, help="Depending on the company, choose whatever you want to receive or send products"), - 'chained_company_id': fields.many2one('res.company', 'Chained Company', help='Set here the belonging company of the chained move'), 'product_id':fields.many2one('product.product','Product'), 'invoice_state': fields.selection([ ("invoiced", "Invoiced"), @@ -120,7 +118,7 @@ class stock_location(osv.osv): if product: for path in product.path_ids: if path.location_from_id.id == location.id: - return path.location_dest_id, path.auto, path.delay, path.journal_id and path.journal_id.id or False, path.chained_company_id and path.chained_companyd_id.id or False, path.picking_type + return path.location_dest_id, path.auto, path.delay, path.journal_id and path.journal_id.id or False, path.company_id and path.company_id.id or False, path.picking_type return super(stock_location, self).chained_location_get(cr, uid, location, partner, product, context) stock_location() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From b140d34b193a2574d11704e5d964ffb830d3d34b Mon Sep 17 00:00:00 2001 From: "nel@tinyerp.com" <> Date: Wed, 16 Jun 2010 12:47:07 +0200 Subject: [PATCH 2/2] [ADD] stock_avg_consommation: for consommation of product by location and by period bzr revid: nel@tinyerp.com-20100616104707-d4tp02d0qvr7wljz --- addons/account/report/__init__.py | 2 +- addons/stock/stock.py | 28 +++-- addons/stock/stock_view.xml | 4 + addons/stock_avg_consommation/__init__.py | 25 +++++ addons/stock_avg_consommation/__openerp__.py | 35 ++++++ .../stock_avg_consommation.py | 100 ++++++++++++++++++ .../stock_avg_consommation_view.xml | 18 ++++ .../stock_avg_consommation/wizard/__init__.py | 24 +++++ .../wizard/stock_avg_consommation_wizard.py | 57 ++++++++++ 9 files changed, 283 insertions(+), 10 deletions(-) create mode 100644 addons/stock_avg_consommation/__init__.py create mode 100644 addons/stock_avg_consommation/__openerp__.py create mode 100644 addons/stock_avg_consommation/stock_avg_consommation.py create mode 100644 addons/stock_avg_consommation/stock_avg_consommation_view.xml create mode 100644 addons/stock_avg_consommation/wizard/__init__.py create mode 100644 addons/stock_avg_consommation/wizard/stock_avg_consommation_wizard.py 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