forked from OCA/stock-logistics-warehouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstock.py
60 lines (52 loc) · 2.63 KB
/
stock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
#################################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 Julius Network Solutions SARL <[email protected]>
#
# 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 = {
}
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 = {}
location_obj = self.pool.get('stock.location')
move_obj = self.pool.get('stock.move')
for inv in self.browse(cr, uid, ids, context=context):
for line in inv.move_ids:
location_id = line.product_id.product_tmpl_id.property_stock_inventory.id
if line.location_id.id == location_id and line.prodlot_id:
move_ids = move_obj.search(cr, uid, [
('prodlot_id', '=', line.prodlot_id.id),
('state', '=', 'done'),
('date', '<=', line.date),
], order='date desc', limit=1)
if move_ids:
move_id = move_obj.browse(cr, uid , move_ids[0])
real_location_id = move_id.location_dest_id and move_id.location_dest_id.id
if real_location_id and real_location_id != location_id:
move_obj.write(cr, uid, line.id, {'location_id': real_location_id})
return res
stock_inventory()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: