~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to msf_partner/product.py

  • Committer: jf
  • Date: 2011-03-23 13:23:55 UTC
  • Revision ID: jf@tempo4-20110323132355-agyf1soy7m5ewatr
Initial Import

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from osv import osv
24
24
from osv import fields
25
25
 
26
 
import decimal_precision as dp
27
 
 
28
26
 
29
27
class product_supplierinfo(osv.osv):
30
28
    _name = 'product.supplierinfo'
31
29
    _inherit = 'product.supplierinfo'
32
30
 
33
 
    def _get_order_id(self, cr, uid, ids, fields, arg, context=None):
34
 
        r = {}
35
 
        for supinfo in self.read(cr, uid, ids, ['sequence']):
36
 
            r[supinfo['id']] = supinfo['sequence']
37
 
        return r
38
 
 
39
 
    def _get_manu_price_dates(self, cr, uid, ids, fields, arg, context=None):
40
 
        if not context:
41
 
            context = {}
42
 
        ret = {}
43
 
        for prod in self.browse(cr, uid, ids):
44
 
            ret[prod.id] = {}
45
 
            ret[prod.id]['check_manufacturer'] = prod.manufacturer_id and True or False
46
 
            ret[prod.id]['get_first_price'] = prod.pricelist_ids and prod.pricelist_ids[0].price or False
47
 
            ret[prod.id]['get_first_currency'] = prod.pricelist_ids and prod.pricelist_ids[0].currency_id and prod.pricelist_ids[0].currency_id.id or False
48
 
            ret[prod.id]['get_till_date'] = False
49
 
            ret[prod.id]['get_from_date'] = False
50
 
            min_qty = False
51
 
            if prod.pricelist_ids:
52
 
                for price in prod.pricelist_ids:
53
 
                    if min_qty is False or price.min_order_qty < min_qty:
54
 
                        if price.valid_till:
55
 
                            ret[prod.id]['get_till_date'] = price.valid_till
56
 
                        if price.valid_from:
57
 
                            ret[prod.id]['get_from_date'] = price.valid_from
58
 
                        min_qty = price.min_order_qty
59
 
        return ret
60
 
 
61
31
    _columns = {
62
32
        'manufacturer_id': fields.many2one('res.partner', string='Manufacturer', domain=[('manufacturer', '=', 1)]),
63
 
        'second_manufacturer_id': fields.many2one('res.partner', string='Second Manufacturer', domain=[('manufacturer', '=', 1)]),
64
 
        'third_manufacturer_id': fields.many2one('res.partner', string='Third Manufacturer', domain=[('manufacturer', '=', 1)]),
65
 
        'company_id': fields.many2one('res.company','Company',select=1),
66
 
        'sequence_bis': fields.function(_get_order_id, method=True, type="integer", help="Assigns the priority to the list of product supplier.", string="Ranking"),
67
 
        'check_manufacturer': fields.function(_get_manu_price_dates, method=True, type="boolean", string="Manufacturer", multi="compt_f"),
68
 
        'get_first_price': fields.function(_get_manu_price_dates, method=True, type="float", string="Indicative Price", digits_compute=dp.get_precision('Purchase Price Computation'), multi="compt_f"),
69
 
        'get_first_currency': fields.function(_get_manu_price_dates, method=True, type="many2one", relation="res.currency", string="Currency", multi="compt_f"),
70
 
        'get_till_date': fields.function(_get_manu_price_dates, method=True, type="date", string="Valid till date", multi="compt_f"),
71
 
        'get_from_date': fields.function(_get_manu_price_dates, method=True, type="date", string="Valid form date", multi="compt_f"),
72
 
        'active': fields.boolean('Active', help="If the active field is set to False, it allows to hide the the supplier info without removing it."),
73
 
    }
74
 
    
75
 
    _defaults = {
76
 
        'company_id': lambda obj, cr, uid, context: obj.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id,
77
 
        'active': True,
78
33
    }
79
34
 
80
35
product_supplierinfo()