~jgrandguillaume-c2c/openobject-addons/multi-company-cost-price

« back to all changes in this revision

Viewing changes to product/pricelist.py

  • Committer: Joël Grand-Guillaume
  • Date: 2010-04-08 09:00:10 UTC
  • mfrom: (2533.3.664)
  • Revision ID: joel.grandguillaume@camptocamp.com-20100408090010-c0pqjan341s18bxs
[MRG] Merge from last trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from tools import config
28
28
from tools.misc import ustr
29
29
from tools.translate import _
 
30
import decimal_precision as dp
 
31
 
30
32
 
31
33
class price_type(osv.osv):
32
34
    """
147
149
        if context and ('date' in context):
148
150
            date = context['date']
149
151
        result = {}
 
152
        result['item_id'] = {}
150
153
        for id in ids:
151
154
            cr.execute('SELECT * ' \
152
155
                    'FROM product_pricelist_version ' \
199
202
            res1 = cr.dictfetchall()
200
203
            
201
204
            for res in res1:
 
205
                item_id = 0
202
206
                if res:
203
207
                    if res['base'] == -1:
204
208
                        if not res['base_pricelist_id']:
247
251
                            price = max(price, price_limit+res['price_min_margin'])
248
252
                        if res['price_max_margin']:
249
253
                            price = min(price, price_limit+res['price_max_margin'])
 
254
                        item_id = res['id']
250
255
                        break    
251
256
 
252
257
                else:
253
258
                    # False means no valid line found ! But we may not raise an
254
259
                    # exception here because it breaks the search
255
260
                    price = False
256
 
            result[id] = price            
 
261
            result[id] = price
 
262
            result['item_id'] = {id: item_id}    
257
263
            if context and ('uom' in context):
258
264
                product = product_obj.browse(cr, uid, prod_id)
259
265
                uom = product.uos_id or product.uom_id
269
275
    _description = "Pricelist Version"
270
276
    _columns = {
271
277
        'pricelist_id': fields.many2one('product.pricelist', 'Price List',
272
 
            required=True, select=True),
 
278
            required=True, select=True, ondelete='cascade'),
273
279
        'name': fields.char('Name', size=64, required=True, translate=True),
274
280
        'active': fields.boolean('Active',
275
281
            help="When a version is duplicated it is set to non active, so that the " \
354
360
 
355
361
    _columns = {
356
362
        'name': fields.char('Rule Name', size=64, help="Explicit rule name for this pricelist line."),
357
 
        'price_version_id': fields.many2one('product.pricelist.version', 'Price List Version', required=True, select=True),
358
 
        'product_tmpl_id': fields.many2one('product.template', 'Product Template', ondelete='cascade', help="Sets a template if this rule only apply to a template of product. Keep empty for all products"),
359
 
        'product_id': fields.many2one('product.product', 'Product', ondelete='cascade', help="Sets a product if this rule only apply to one product. Keep empty for all products"),
360
 
        'categ_id': fields.many2one('product.category', 'Product Category', ondelete='cascade', help="Sets a category of product if this rule only apply to products of a category and his childs. Keep empty for all products"),
 
363
        'price_version_id': fields.many2one('product.pricelist.version', 'Price List Version', required=True, select=True, ondelete='cascade'),
 
364
        'product_tmpl_id': fields.many2one('product.template', 'Product Template', ondelete='cascade', help="Set a template if this rule only apply to a template of product. Keep empty for all products"),
 
365
        'product_id': fields.many2one('product.product', 'Product', ondelete='cascade', help="Set a product if this rule only apply to one product. Keep empty for all products"),
 
366
        'categ_id': fields.many2one('product.category', 'Product Category', ondelete='cascade', help="Set a category of product if this rule only apply to products of a category and his childs. Keep empty for all products"),
361
367
 
362
368
        'min_quantity': fields.integer('Min. Quantity', required=True, help="The rule only applies if the partner buys/sells more than this quantity."),
363
369
        'sequence': fields.integer('Sequence', required=True, help="Gives the sequence order when displaying a list of pricelist items."),
365
371
        'base_pricelist_id': fields.many2one('product.pricelist', 'If Other Pricelist'),
366
372
 
367
373
        'price_surcharge': fields.float('Price Surcharge',
368
 
            digits=(16, int(config['price_accuracy']))),
 
374
            digits_compute= dp.get_precision('Sale Price')),
369
375
        'price_discount': fields.float('Price Discount', digits=(16,4)),
370
376
        'price_round': fields.float('Price Rounding',
371
 
            digits=(16, int(config['price_accuracy'])),
 
377
            digits_compute= dp.get_precision('Sale Price'),
372
378
            help="Sets the price so that it is a multiple of this value.\n" \
373
379
              "Rounding is applied after the discount and before the surcharge.\n" \
374
380
              "To have prices that end in 9.99, set rounding 10, surcharge -0.01" \
375
381
            ),
376
382
        'price_min_margin': fields.float('Min. Price Margin',
377
 
            digits=(16, int(config['price_accuracy']))),
 
383
            digits_compute= dp.get_precision('Sale Price')),
378
384
        'price_max_margin': fields.float('Max. Price Margin',
379
 
            digits=(16, int(config['price_accuracy']))),
 
385
            digits_compute= dp.get_precision('Sale Price')),
380
386
        'company_id': fields.related('price_version_id','company_id',type='many2one',
381
387
            readonly=True, relation='res.company', string='Company', store=True)
382
388
    }