Files
stock-logistics-warehouse/stock_inventory_extended/stock.py
2012-03-07 13:56:37 +01:00

96 lines
4.0 KiB
Python

# -*- coding: utf-8 -*-
#################################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 Julius Network Solutions SARL <contact@julius.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#################################################################################
from osv import fields, osv
from tools.translate import _
class stock_inventory(osv.osv):
_inherit = "stock.inventory"
_columns = {
'comments':fields.text('Comments'),
}
def action_confirm(self, cr, uid, ids, context=None):
""" Confirm the inventory and writes its finished date
@return: True
"""
res = super(stock_inventory, self).action_confirm(cr, uid, ids, context)
if context is None:
context = {}
# to perform the correct inventory corrections we need analyze stock location by
# location, never recursively, so we use a special context
product_context = dict(context, compute_child=False)
location_obj = self.pool.get('stock.location')
for inv in self.browse(cr, uid, ids, context=context):
move_ids = []
self.write(cr, uid, [inv.id], {'move_ids': [(6, 0, move_ids)]})
for line in inv.inventory_line_id:
pid = line.product_id.id
date = line.date or inv.date
product_context.update(uom=line.product_uom.id, date=date, to_date=date, prodlot_id=line.prod_lot_id.id)
amount = location_obj._product_get(cr, uid, line.location_id.id, [pid], product_context)[pid]
change = line.product_qty - amount
lot_id = line.prod_lot_id.id
if change:
location_id = line.product_id.product_tmpl_id.property_stock_inventory.id
value = {
'name': 'INV:' + str(line.inventory_id.id) + ':' + line.inventory_id.name,
'product_id': line.product_id.id,
'product_uom': line.product_uom.id,
'prodlot_id': lot_id,
'date': date,
'note': line.note or inv.comments or False,
}
if change > 0:
value.update( {
'product_qty': change,
'location_id': location_id,
'location_dest_id': line.location_id.id,
})
else:
value.update( {
'product_qty': -change,
'location_id': line.location_id.id,
'location_dest_id': location_id,
})
move_ids.append(self._inventory_line_hook(cr, uid, line, value))
message = _('Inventory') + " '" + inv.name + "' "+ _("is done.")
self.log(cr, uid, inv.id, message)
self.write(cr, uid, [inv.id], {'state': 'confirm', 'move_ids': [(6, 0, move_ids)]})
return res
stock_inventory()
class stock_inventory_line(osv.osv):
_inherit = "stock.inventory.line"
_columns = {
'date': fields.datetime('Date'),
'note': fields.text('Notes'),
}
stock_inventory_line()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: