~savoirfairelinux-openerp/openerp-usa/openerp-usa

« back to all changes in this revision

Viewing changes to reports_address_us/report/picking_us.py

  • Committer: Sinoj Sebastian
  • Date: 2011-12-20 08:13:31 UTC
  • Revision ID: ssebastian@novapointgroup.com-20111220081331-10la9pb56q41n8rd
Updated all modules with latest versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
        super(picking, self).__init__(cr, uid, name, context=context)
30
30
        self.localcontext.update({
31
31
            'time': time,
32
 
            'get_qtytotal':self._get_qtytotal
 
32
            'get_qtytotal':self._get_qtytotal,
 
33
            
 
34
            '_get_parent':self._get_parent,
 
35
            '_get_childs':self._get_childs,
 
36
            '_get_move_lines' : self._get_move_lines,
 
37
            
33
38
        })
 
39
        
 
40
    def _get_move_lines(self, pick_id):
 
41
        cr  = self.cr
 
42
        uid = self.uid
 
43
        context = self.localcontext
 
44
        pick = self.pool.get('stock.picking').browse(cr, uid, pick_id)
 
45
        sale = pick.sale_id
 
46
        res=[]
 
47
        
 
48
        if not sale:
 
49
            for move in pick.move_lines:
 
50
                res.append({
 
51
                                'name'      : '[' + move.product_id.default_code + '] ' + move.product_id.name,
 
52
                                'lot'       : move.prodlot_id and move.prodlot_id.name or '',
 
53
                                'state'     : move.state,
 
54
                                'location'  : move.location_id and move.location_id.name or '',
 
55
                                'quantity'  : self.formatLang(move.product_qty) + ' ' + move.product_uom.name,
 
56
                                'parent'    : False,
 
57
                                'style'     : 'normal',
 
58
                            })
 
59
            return res
 
60
        
 
61
        move_datas = []
 
62
        
 
63
#===============================================================================
 
64
#        move_lines = self.pool.get('stock.move').search(cr, uid, [('picking_id','=',pick.id)], order="parent_bom_id,id desc", offset=0,  limit=None,
 
65
#            context=context, count=False )
 
66
#        
 
67
#===============================================================================
 
68
        
 
69
        self.cr.execute("SELECT id from stock_move where picking_id='%s' order by parent_bom_id;"%(pick.id))
 
70
        fetchdata = self.cr.fetchall() or None
 
71
        if not fetchdata:
 
72
            move_lines = []
 
73
        if isinstance(fetchdata, list):
 
74
            move_lines = [t[0] for t in fetchdata]
 
75
        else:
 
76
            move_lines = fetchdata[0]
 
77
        
 
78
        moves = self.pool.get('stock.move').browse(cr, uid, move_lines, context=context)
 
79
        
 
80
        for move in moves:
 
81
            move_datas.append({
 
82
                                    'object'    : move,
 
83
                                    'state'     : 'init', # added, assigned bom
 
84
                                    'bom_type'  : '',
 
85
                                    'bom'       : False,
 
86
                                    'order_line': False,
 
87
                                    'parent_product' : False
 
88
                               })
 
89
        order_data = {}
 
90
        for i, move_data in enumerate(move_datas):
 
91
            move=move_data['object']
 
92
            for order_line in sale.order_line:
 
93
                if order_line.product_id and order_line.product_id.bom_ids:
 
94
                    bom=order_line.product_id.bom_ids[0]
 
95
                    if bom.type=='assembly':
 
96
                        f=0
 
97
                        #Check the product present in bom lines
 
98
                        for bom_line in bom.bom_lines:
 
99
                            if bom_line.product_id.id == move.product_id.id:
 
100
                               f=1
 
101
                               break
 
102
                        # if product is a sub component 
 
103
                        if f:
 
104
                            order_data[order_line.id]  = 1
 
105
                            move_datas[i]['parent_product'] =  order_line.product_id.id
 
106
                            move_datas[i]['bom'] = bom_line
 
107
                            move_datas[i]['bom_type'] = 'assembly'
 
108
                            move_datas[i]['order_line'] = order_line
 
109
            
 
110
        
 
111
        for i, move_data in enumerate(move_datas):
 
112
            move=move_data['object']
 
113
            if move_data['bom_type'] == 'assembly':
 
114
                if order_data[move_data['order_line'].id]:
 
115
                    res.append({
 
116
                                'name' : ' [' + move_data['order_line'].product_id.code + '] ' +  move_data['order_line'].product_id.name,
 
117
                                'lot'       : '',
 
118
                                'state'     : '',
 
119
                                'location'  : '',
 
120
                                'quantity'  : '',
 
121
                                'parent'    : True,
 
122
                                'style'     : 'parent',
 
123
                            })
 
124
                    order_data[move_data['order_line'].id] = 0
 
125
            
 
126
                res.append({
 
127
                                'name'      : '[' + move.product_id.default_code + '] ' + move.product_id.name,
 
128
                                'lot'       : move.prodlot_id and move.prodlot_id.name or '',
 
129
                                'state'     : move.state,
 
130
                                'location'  : move.location_id and move.location_id.name or '',
 
131
                                'quantity'  : self.formatLang(move.product_qty) + ' ' + move.product_uom.name,
 
132
                                'parent'    : False,
 
133
                                'style'     : 'child',
 
134
                            })
 
135
            else:
 
136
                res.append({
 
137
                            'name'      : '[' + move.product_id.default_code + '] ' + move.product_id.name,
 
138
                            'lot'       : move.prodlot_id and move.prodlot_id.name or '',
 
139
                            'state'     : move.state,
 
140
                            'location'  : move.location_id and move.location_id.name or '',
 
141
                            'quantity'  : self.formatLang(move.product_qty) + ' ' + move.product_uom.name,
 
142
                            'parent'    : False,
 
143
                            'style'     : 'normal',
 
144
                        })
 
145
        
 
146
        return res
 
147
 
 
148
    def _get_parent(self,pick_id):
 
149
        cr=self.cr
 
150
        uid=self.uid
 
151
        context=self.localcontext
 
152
        move_obj=self.pool.get('stock.move')
 
153
        move_ids=move_obj.search(cr,uid,[('picking_id','=',pick_id),("parent_bom_id","!=",False)])
 
154
        moves=move_obj.browse(cr,uid,move_ids,context=context)
 
155
        for move in moves:
 
156
            production=move.kit_id
 
157
            if production:
 
158
                product_qty=production.product_qty
 
159
                sale_id=move.sale_id.id
 
160
 
 
161
                parent_move_ids=move_obj.search(cr,uid,[("sale_id","=",sale_id),
 
162
                                                       ("product_qty","=",product_qty),
 
163
                                                       ("product_id","=",production.product_id.id)])
 
164
                parent_moves=move_obj.browse(cr,uid,parent_move_ids)
 
165
                #print "parent_move_ids",parent_move_ids
 
166
#                return {'child_moves':moves,"parent_moves":parent_moves}
 
167
                return parent_moves
 
168
                break
 
169
            
 
170
            
 
171
    def _get_childs(self,pick_id):
 
172
        cr=self.cr
 
173
        uid=self.uid
 
174
        context=self.localcontext
 
175
        move_obj=self.pool.get('stock.move')
 
176
        move_ids=move_obj.search(cr,uid,[('picking_id','=',pick_id),("parent_bom_id","!=",False)])
 
177
        print move_ids,'====================move_ids================================'
 
178
        return move_obj.browse(cr,uid,move_ids,context=context)
 
179
 
34
180
    def _get_qtytotal(self,move_lines):
35
181
        total = 0.0
36
182
        uom = move_lines[0].product_uom.name