23
23
from osv import osv
24
24
from osv import fields
26
import decimal_precision as dp
29
27
class product_supplierinfo(osv.osv):
30
28
_name = 'product.supplierinfo'
31
29
_inherit = 'product.supplierinfo'
33
def _get_order_id(self, cr, uid, ids, fields, arg, context=None):
35
for supinfo in self.read(cr, uid, ids, ['sequence']):
36
r[supinfo['id']] = supinfo['sequence']
39
def _get_manu_price_dates(self, cr, uid, ids, fields, arg, context=None):
43
for prod in self.browse(cr, uid, ids):
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
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:
55
ret[prod.id]['get_till_date'] = price.valid_till
57
ret[prod.id]['get_from_date'] = price.valid_from
58
min_qty = price.min_order_qty
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."),
76
'company_id': lambda obj, cr, uid, context: obj.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id,
80
35
product_supplierinfo()