~openbig/bigconsulting/added_report_barcode_check

« back to all changes in this revision

Viewing changes to packing_barcode_check/packing_barcode_check.py

  • Committer: husen
  • Date: 2010-06-23 15:56:43 UTC
  • mfrom: (25.1.4 bigconsulting)
  • Revision ID: husen@husen-laptop-20100623155643-19re207vkk1u532e
added barcode_check module

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (c) 2009 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
 
6
#                       Jordi Esteve <jesteve@zikzakmedia.com>
 
7
#    $Id$
 
8
#
 
9
#    This program is free software: you can redistribute it and/or modify
 
10
#    it under the terms of the GNU General Public License as published by
 
11
#    the Free Software Foundation, either version 3 of the License, or
 
12
#    (at your option) any later version.
 
13
#
 
14
#    This program is distributed in the hope that it will be useful,
 
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#    GNU General Public License for more details.
 
18
#
 
19
#    You should have received a copy of the GNU General Public License
 
20
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
#
 
22
##############################################################################
 
23
 
 
24
from osv import osv, fields
 
25
from tools.sql import drop_view_if_exists
 
26
 
 
27
class stock_picking(osv.osv):
 
28
    _name='stock.picking'
 
29
    _inherit='stock.picking'
 
30
    
 
31
    def _total_quantity(self, cr, uid, ids, name, args, context):
 
32
        result = {}
 
33
        stock_move_obj = self.pool.get("stock.move")
 
34
        for id in ids:
 
35
            tot_qty = 0.0
 
36
            stock_move_ids= stock_move_obj.search(cr, uid, [('picking_id','=',id)]) 
 
37
            for move_id in stock_move_ids:
 
38
                move_data = stock_move_obj.browse(cr, uid, move_id)
 
39
                tot_qty += move_data.product_qty
 
40
            result[id] = tot_qty
 
41
        return result
 
42
    
 
43
    def _scanned_quantity(self, cr, uid, ids, name, args, context):
 
44
        result = {}
 
45
        for id in ids:
 
46
            scanned_qty = 0.0
 
47
            scanned_data = self.browse(cr, uid, id)
 
48
            for scanned_data in scanned_data.scaned_ids:
 
49
                scanned_qty += scanned_data.scan_quantity
 
50
            result[id] = scanned_qty
 
51
        return result
 
52
    
 
53
    def _to_be_scanned_quantity(self, cr, uid, ids, name, args, context):
 
54
        result = {}
 
55
        for id in ids:
 
56
            tobe_scanned_qty = 0.0
 
57
            scanned_data = self.browse(cr, uid, id)
 
58
            tobe_scanned_qty = scanned_data.total_quantity - scanned_data.scanned_quantity
 
59
            result[id] = tobe_scanned_qty
 
60
        return result
 
61
    
 
62
    _columns = {
 
63
                'ean' : fields.char("EAN", size=64,),
 
64
                'total_quantity':fields.function(_total_quantity, method=True, string='Total Quantity'),
 
65
                'scanned_quantity': fields.function(_scanned_quantity, method=True, string='Scanned Quantity'),
 
66
                'to_be_scanned_quantity':fields.function(_to_be_scanned_quantity, method=True, string='To Be Scanned Quantity'),
 
67
                'tobe_scan_ids':fields.one2many('tobe.scanned.stock', 'tobe_picking_id', 'To Be'),
 
68
                'scaned_ids':fields.one2many('scanned.stock', 'scanned_picking_id', 'Scanned Picking',),
 
69
            }
 
70
    _defaults = {
 
71
      'scanned_quantity' : lambda *a:0.0,
 
72
      
 
73
      }
 
74
stock_picking()
 
75
 
 
76
class stock_move(osv.osv):
 
77
    _inherit = "stock.move"
 
78
    _columns = {
 
79
       'scaned_qty':fields.float("Scanned Qty"),
 
80
       }
 
81
    
 
82
    _defaults = {
 
83
      'scaned_qty' : lambda *a:0.0,
 
84
      
 
85
      }
 
86
stock_move()
 
87
 
 
88
class tobe_scanned_stock(osv.osv):
 
89
    _name = "tobe.scanned.stock"
 
90
    _auto = False
 
91
    _columns = {
 
92
        'tobe_picking_id': fields.many2one('stock.picking', 'Stock Picking',),        
 
93
        'product_name':fields.many2one('product.product','Product Name', size=64),
 
94
        'lot_number':fields.many2one('stock.production.lot','Lot Number', size=64),
 
95
        'quantity':fields.float("Quantity"),
 
96
        'scan_quantity':fields.float("Scan Quantity"),
 
97
    }
 
98
    
 
99
    def init(self, cr):
 
100
        drop_view_if_exists(cr, 'tobe_scanned_stock')
 
101
        cr.execute("""
 
102
            CREATE OR REPLACE VIEW tobe_scanned_stock AS (
 
103
                SELECT
 
104
                    l.id AS id,
 
105
                    l.picking_id AS tobe_picking_id,
 
106
                    sum(l.scaned_qty) AS scan_quantity,
 
107
                    sum(l.product_qty) AS quantity,
 
108
                    l.prodlot_id AS lot_number,
 
109
                    l.product_id AS product_name
 
110
                FROM
 
111
                    stock_move l
 
112
                WHERE
 
113
                    l.scaned_qty != l.product_qty
 
114
                GROUP BY
 
115
                    l.product_id,l.prodlot_id,l.picking_id, l.id
 
116
            )
 
117
        """)
 
118
tobe_scanned_stock()
 
119
 
 
120
class scanned_stock(osv.osv):
 
121
    _name = "scanned.stock"
 
122
    _auto = False
 
123
    _columns = {
 
124
        'scanned_picking_id': fields.many2one('stock.picking', 'Stock Picking',),        
 
125
        'product_name':fields.many2one('product.product','Product Name', size=64),
 
126
        'lot_number':fields.many2one('stock.production.lot','Lot Number', size=64),
 
127
        'quantity':fields.float("Quantity"),
 
128
        'scan_quantity':fields.float("Scan Quantity"),
 
129
    }
 
130
    
 
131
    def init(self, cr):
 
132
        drop_view_if_exists(cr, 'scanned_stock')
 
133
        cr.execute("""
 
134
            CREATE OR REPLACE VIEW scanned_stock AS (
 
135
                SELECT
 
136
                    l.id AS id,
 
137
                    l.picking_id AS scanned_picking_id,
 
138
                    sum(l.scaned_qty) AS scan_quantity,
 
139
                    sum(l.product_qty) AS quantity,
 
140
                    l.prodlot_id AS lot_number,
 
141
                    l.product_id AS product_name
 
142
                FROM
 
143
                    stock_move l
 
144
                WHERE
 
145
                    l.scaned_qty = l.product_qty
 
146
                GROUP BY
 
147
                    l.product_id,l.prodlot_id,l.picking_id, l.id
 
148
            )
 
149
        """)
 
150
scanned_stock()
 
151
 
 
152
 
 
153
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'