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

« back to all changes in this revision

Viewing changes to assembly_bom/stock.py

  • Committer: Sinoj Sebastian
  • Date: 2011-06-15 07:11:15 UTC
  • Revision ID: ssebastian@novapointgroup.com-20110615071115-kn3eq2yl9ktber45
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import netsvc
25
25
import datetime
26
26
import time
 
27
from tools.translate import _
27
28
 
28
29
class StockMove(osv.osv):
29
30
    _inherit = 'stock.move'
119
120
              'production_ids': fields.many2many('mrp.production', 'mrp_production_move_ids', 'move_id', 'production_id', 'Related Production'),
120
121
              'parent_bom_id':fields.many2one("mrp.bom",'Related Bom')
121
122
              }
 
123
    def onchange_quantity(self, cr, uid, ids, product_id, product_qty,
 
124
                          product_uom, product_uos):
 
125
        """ On change of product quantity finds UoM and UoS quantities
 
126
        @param product_id: Product id
 
127
        @param product_qty: Changed Quantity of product
 
128
        @param product_uom: Unit of measure of product
 
129
        @param product_uos: Unit of sale of product
 
130
        @return: Dictionary of values
 
131
        """
 
132
        result=super(StockMove,self).onchange_quantity(cr, uid, ids, product_id, product_qty, product_uom, product_uos)
 
133
        print result
 
134
        if (not product_id) or (product_qty <=0.0):
 
135
            return result
 
136
        
 
137
        product_obj = self.pool.get('product.product').browse(cr, uid, [product_id])[0]
 
138
        uom2 = product_obj.uom_id
 
139
        if (product_obj.type=='product') and (product_obj.virtual_available * uom2.factor < product_qty * product_obj.uom_id.factor) \
 
140
                  and (product_obj.procure_method=='make_to_stock'):
 
141
                    warning = {
 
142
                        'title': _('Not enough stock !'),
 
143
                        'message': _('You plan to move %.2f %s but you only have %.2f %s available !\nThe real stock is %.2f %s. (without reservations)') %
 
144
                            (product_qty, uom2 and uom2.name or product_obj.uom_id.name,
 
145
                             max(0,product_obj.virtual_available), product_obj.uom_id.name,
 
146
                             max(0,product_obj.qty_available), product_obj.uom_id.name)
 
147
                    }     
 
148
                    result['warning'] = warning
 
149
                    
 
150
        if (product_obj.type=='product') and product_obj.procure_method=='make_to_order':
 
151
            bom_id = self.pool.get('mrp.bom').search(cr, uid, [
 
152
                        ('product_id', '=', product_obj.id),
 
153
                        ('bom_id', '=', False),
 
154
                        ('type', '=', 'assembly')])[0]
 
155
            bom_obj = self.pool.get('mrp.bom').browse(cr, uid, bom_id)
 
156
            
 
157
            if bom_obj and (bom_obj.bom_stock_value  < product_qty * product_obj.uom_id.factor) \
 
158
                  and (product_obj.procure_method=='make_to_order'):
 
159
                    warning = {
 
160
                        'title': _('Not enough stock !'),
 
161
                        'message': _('You plan to move %.2f %s but you only have %.2f %s available !\nThe real stock is %.2f %s. (without reservations)') %
 
162
                            (product_qty, uom2 and uom2.name or product_obj.uom_id.name,
 
163
                             max(0,bom_obj.bom_stock_value), product_obj.uom_id.name,
 
164
                             max(0,product_obj.qty_available), product_obj.uom_id.name)
 
165
                    }     
 
166
                    result['warning'] = warning                    
 
167
                    
 
168
        return result
 
169
    def onchange_product_id(self, cr, uid, ids, prod_id=False, loc_id=False,
 
170
                            loc_dest_id=False, address_id=False,product_qty=0):
 
171
        """ On change of product id, .
 
172
        @param prod_id: Changed Product id
 
173
        @param loc_id: Source location id
 
174
        @param loc_id: Destination location id
 
175
        @param address_id: Address id of partner
 
176
        @param product_qty: Product Quantity
 
177
        @return: Dictionary of values
 
178
        """
 
179
        warning = {}
 
180
        res=super(StockMove,self).onchange_product_id(cr, uid, ids, prod_id=prod_id, loc_id=loc_id,
 
181
                            loc_dest_id=loc_dest_id, address_id=address_id)
 
182
        if not prod_id:
 
183
            return res
 
184
 
 
185
        product_obj = self.pool.get('product.product').browse(cr, uid, [prod_id])[0]
 
186
        uom2 = product_obj.uom_id
 
187
            
 
188
        
 
189
        
 
190
        
 
191
        if (product_obj.type=='product') and (product_obj.virtual_available * uom2.factor < product_qty * product_obj.uom_id.factor) \
 
192
                  and (product_obj.procure_method=='make_to_stock'):
 
193
                    warning = {
 
194
                        'title': _('Not enough stock !'),
 
195
                        'message': _('You plan to move %.2f %s but you only have %.2f %s available !\nThe real stock is %.2f %s. (without reservations)') %
 
196
                            (product_qty, uom2 and uom2.name or product_obj.uom_id.name,
 
197
                             max(0,product_obj.virtual_available), product_obj.uom_id.name,
 
198
                             max(0,product_obj.qty_available), product_obj.uom_id.name)
 
199
                    }     
 
200
                    res['warning'] = warning
 
201
        if (product_obj.type=='product') and product_obj.procure_method=='make_to_order':
 
202
            bom_id = self.pool.get('mrp.bom').search(cr, uid, [
 
203
                        ('product_id', '=', product_obj.id),
 
204
                        ('bom_id', '=', False),
 
205
                        ('type', '=', 'assembly')])[0]
 
206
            bom_obj = self.pool.get('mrp.bom').browse(cr, uid, bom_id)
 
207
            if bom_id and (bom_obj.bom_stock_value  < product_qty * product_obj.uom_id.factor):
 
208
                    warning = {
 
209
                        'title': _('Not enough stock !'),
 
210
                        'message': _('You plan to move %.2f %s but you only have %.2f %s available !\nThe real stock is %.2f %s. (without reservations)') %
 
211
                            (product_qty, uom2 and uom2.name or product_obj.uom_id.name,
 
212
                             max(0,bom_obj.bom_stock_value), product_obj.uom_id.name,
 
213
                             max(0,product_obj.qty_available), product_obj.uom_id.name)
 
214
                    }     
 
215
                    res['warning'] = warning
 
216
        return res
 
217
    _defaults = {
 
218
        'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
 
219
        'date_expected': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
 
220
    }
 
221
    
122
222
StockMove()
123
223
 
124
224
 
264
364
        except Exception, e:
265
365
            print e
266
366
        return True
 
367
    _defaults = {
 
368
        'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
 
369
    }
267
370
 
268
371
 
269
372
stock_picking()
294
397
            return super(location, self).search(cr, uid, args=args, offset=offset, limit=limit, order=order,
295
398
                context=context, count=count)
296
399
location()
 
400
 
 
401
 
 
402
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
403