~numerigraphe-team/stock-logistic-warehouse/7.0-inventory-location

« back to all changes in this revision

Viewing changes to stock_inventory_existing_lines/stock.py

  • Committer: Mathieu Vatel
  • Date: 2012-03-07 12:56:37 UTC
  • Revision ID: mathieu@julius.fr-20120307125637-oz14go5k32kyqn2f
Extra modules Julius V1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#################################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2011 Julius Network Solutions SARL <contact@julius.fr>
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
#
 
20
#################################################################################
 
21
 
 
22
from osv import fields, osv
 
23
from tools.translate import _
 
24
 
 
25
import decimal_precision as dp
 
26
 
 
27
class stock_inventory(osv.osv):
 
28
    _inherit = "stock.inventory"
 
29
    
 
30
    _columns = {
 
31
        'inventory_line_id2': fields.one2many('stock.inventory.line2', 'inventory_id', 'Inventories', states={'done': [('readonly', True)]}),
 
32
    }
 
33
    
 
34
    def action_confirm(self, cr, uid, ids, context=None):
 
35
        if context is None:
 
36
            context = {}
 
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)
 
40
 
 
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):
 
45
            move_ids = []
 
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:
 
49
#                    continue
 
50
                if not line.product_qty:
 
51
                    continue
 
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]
 
56
                if not amount:
 
57
                    continue
 
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)
 
64
        return res
 
65
 
 
66
stock_inventory()
 
67
 
 
68
#class stock_move(osv.osv):
 
69
#    _inherit = "stock.move"
 
70
#    
 
71
#    _columns = {
 
72
#        'inventory_type': fields.selection([('in','In'),('out','Out')], 'Inventory type')
 
73
#    }
 
74
#stock_move()
 
75
 
 
76
class stock_inventory_line2(osv.osv):
 
77
    _name = "stock.inventory.line2"
 
78
    
 
79
    _columns = {
 
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),
 
88
    }
 
89
 
 
90
stock_inventory_line2()
 
91
 
 
92
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'