1
# -*- coding: utf-8 -*-
2
#################################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 Julius Network Solutions SARL <contact@julius.fr>
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#################################################################################
22
from osv import fields, osv
23
from tools.translate import _
25
import decimal_precision as dp
27
class stock_inventory(osv.osv):
28
_inherit = "stock.inventory"
31
'inventory_line_id2': fields.one2many('stock.inventory.line2', 'inventory_id', 'Inventories', states={'done': [('readonly', True)]}),
34
def action_confirm(self, cr, uid, ids, context=None):
37
''' to perform the correct inventory corrections we need analyze stock location by
38
location, never recursively, so we use a special context '''
39
product_context = dict(context, compute_child=False)
41
location_obj = self.pool.get('stock.location')
42
line_obj = self.pool.get('stock.inventory.line')
43
line2_obj = self.pool.get('stock.inventory.line2')
44
for inv in self.browse(cr, uid, ids, context=context):
46
for line in inv.inventory_line_id:
47
# ''' if the production lot is tracked but do not have a serial code then it is not taken into account '''
48
# if line.product_id.categ_id.tracked and not line.prod_lot_id:
50
if not line.product_qty:
52
pid = line.product_id.id
53
date = line.date or inv.date
54
product_context.update(uom=line.product_uom.id, date=date, to_date=date, prodlot_id=line.prod_lot_id.id)
55
amount = location_obj._product_get(cr, uid, line.location_id.id, [pid], product_context)[pid]
58
val_qty = min(line.product_qty,amount)
59
if val_qty and val_qty > 0:
60
vals = line_obj.copy_data(cr, uid, line.id)
61
line2_obj.create(cr, uid, vals)
62
# location_id = line.product_id.product_tmpl_id.property_stock_inventory.id
63
res = super(stock_inventory, self).action_confirm(cr, uid, ids, context)
68
#class stock_move(osv.osv):
69
# _inherit = "stock.move"
72
# 'inventory_type': fields.selection([('in','In'),('out','Out')], 'Inventory type')
76
class stock_inventory_line2(osv.osv):
77
_name = "stock.inventory.line2"
80
'inventory_id': fields.many2one('stock.inventory', 'Inventory', ondelete='cascade', select=True),
81
'location_id': fields.many2one('stock.location', 'Location', required=True),
82
'product_id': fields.many2one('product.product', 'Product', required=True, select=True),
83
'product_uom': fields.many2one('product.uom', 'Product UOM', required=True),
84
'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product UoM')),
85
'company_id': fields.related('inventory_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, select=True, readonly=True),
86
'prod_lot_id': fields.many2one('stock.production.lot', 'Production Lot', domain="[('product_id','=',product_id)]"),
87
'state': fields.related('inventory_id', 'state', type='char', string='State',readonly=True),
90
stock_inventory_line2()
92
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'