~agilebg/openerp-product-attributes/adding_product_pack_7

« back to all changes in this revision

Viewing changes to product_pack/pack.py

  • Committer: Alex Comba
  • Date: 2013-08-26 12:37:15 UTC
  • Revision ID: alex.comba@agilebg.com-20130826123715-xxvw3lvhvk4e9vlx
[REM] empty spaces close to arguments

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    _name = 'product.pack.line'
29
29
    _rec_name = 'product_id'
30
30
    _columns = {
31
 
        'parent_product_id': fields.many2one( 'product.product', 'Parent Product', ondelete='cascade', required=True ),
32
 
        'quantity': fields.float( 'Quantity', required=True ),
33
 
        'product_id': fields.many2one( 'product.product', 'Product', required=True ),
 
31
        'parent_product_id': fields.many2one('product.product', 'Parent Product', ondelete='cascade', required=True),
 
32
        'quantity': fields.float('Quantity', required=True),
 
33
        'product_id': fields.many2one('product.product', 'Product', required=True),
34
34
    }
35
35
 
36
36
class product_product(orm.Model):
37
37
    _inherit = 'product.product'
38
38
    _columns = {
39
 
        'stock_depends': fields.boolean( 'Stock depends of components', help='Mark if pack stock is calcualted from component stock' ),
40
 
        'pack_fixed_price': fields.boolean( 'Pack has fixed price', help='Mark this field if the public price of the pack should be fixed. Do not mark it if the price should be calculated from the sum of the prices of the products in the pack.' ),
41
 
        'pack_line_ids': fields.one2many( 'product.pack.line','parent_product_id', 'Pack Products', help='List of products that are part of this pack.' ),
 
39
        'stock_depends': fields.boolean('Stock depends of components', help='Mark if pack stock is calcualted from component stock'),
 
40
        'pack_fixed_price': fields.boolean('Pack has fixed price', help='Mark this field if the public price of the pack should be fixed. Do not mark it if the price should be calculated from the sum of the prices of the products in the pack.'),
 
41
        'pack_line_ids': fields.one2many('product.pack.line','parent_product_id', 'Pack Products', help='List of products that are part of this pack.'),
42
42
    }
43
43
 
44
44
    def get_product_available(self, cr, uid, ids, context=None):
45
45
        """ Calulate stock for packs, return  maximum stock that lets complete pack """
46
46
        result={}
47
 
        for product in self.browse( cr, uid, ids, context=context ):
 
47
        for product in self.browse(cr, uid, ids, context=context):
48
48
            stock = super(product_product, self).get_product_available(cr, uid, [product.id], context=context)
49
49
 
50
50
            # Check if product stock depends on it's subproducts stock.
145
145
            last_had_children = False
146
146
            for line in order.order_line:
147
147
                if last_had_children and not line.pack_parent_line_id:
148
 
                    reorder.append( line.id )
 
148
                    reorder.append(line.id)
149
149
                    if line.product_id.pack_line_ids and not order.id in updated_orders:
150
 
                        updated_orders.append( order.id )
 
150
                        updated_orders.append(order.id)
151
151
                    continue
152
152
 
153
153
                sequence += 1
231
231
 
232
232
                    # It's a control for the case that the nan_external_prices was installed with the product pack
233
233
                    if 'prices_used' in line:
234
 
                        vals[ 'prices_used' ] = line.prices_used
 
234
                        vals['prices_used'] = line.prices_used
235
235
 
236
236
                    self.pool.get('sale.order.line').create(cr, uid, vals, context)
237
237
                    if not order.id in updated_orders:
238
 
                        updated_orders.append( order.id )
 
238
                        updated_orders.append(order.id)
239
239
 
240
240
                for id in reorder:
241
241
                    sequence += 1
247
247
 
248
248
            # Try to expand again all those orders that had a pack in this iteration.
249
249
            # This way we support packs inside other packs.
250
 
            self.expand_packs(cr, uid, ids, context, depth+1)
 
250
            self.expand_packs(cr, uid, ids, context, depth + 1)
251
251
        return
252
252
 
253
253
 
301
301
            last_had_children = False
302
302
            for line in order.order_line:
303
303
                if last_had_children and not line.pack_parent_line_id:
304
 
                    reorder.append( line.id )
 
304
                    reorder.append(line.id)
305
305
                    if line.product_id.pack_line_ids and not order.id in updated_orders:
306
 
                        updated_orders.append( order.id )
 
306
                        updated_orders.append(order.id)
307
307
                    continue
308
308
 
309
309
                sequence += 1
351
351
 
352
352
                    vals = {
353
353
                        'order_id': order.id,
354
 
                        'name': '%s%s' % ('> '* (line.pack_depth+1), subproduct_name),
 
354
                        'name': '%s%s' % ('> '* (line.pack_depth + 1), subproduct_name),
355
355
                        'date_planned': line.date_planned or 0.0,
356
356
                        'sequence': sequence,
357
357
                        'product_id': subproduct.id,
368
368
 
369
369
                    # It's a control for the case that the nan_external_prices was installed with the product pack
370
370
                    if 'prices_used' in line:
371
 
                        vals[ 'prices_used' ] = line.prices_used
 
371
                        vals['prices_used'] = line.prices_used
372
372
 
373
373
                    self.pool.get('purchase.order.line').create(cr, uid, vals, context)
374
374
                    if not order.id in updated_orders:
375
 
                        updated_orders.append( order.id )
 
375
                        updated_orders.append(order.id)
376
376
 
377
377
                for id in reorder:
378
378
                    sequence += 1
384
384
 
385
385
            # Try to expand again all those orders that had a pack in this iteration.
386
386
            # This way we support packs inside other packs.
387
 
            self.expand_packs(cr, uid, ids, context, depth+1)
 
387
            self.expand_packs(cr, uid, ids, context, depth + 1)
388
388
        return
 
 
b'\\ No newline at end of file'