7
class product(osv.osv):
8
_name = "tiny_purchase.product"
10
'name': fields.char('Name', size=64),
11
'price': fields.float('Price'),
16
_name = "tiny_purchase.order"
19
'name': fields.date('Date'),
20
'user_id': fields.many2one('res.users', 'User', required=True),
21
'line_ids': fields.one2many('tiny_purchase.line', 'order_id', 'Lines'),
22
'state': fields.selection([('draft', 'Draft'), ('confirmed', 'Confirmed'), ('done', 'Done')], 'State'),
26
'name': lambda *a: time.strftime('%Y-%m-%d'),
27
'user_id': lambda self, cr, uid, context: uid,
28
'state': lambda *a: 'draft',
33
_name = "tiny_purchase.line"
34
_rec_name = "product_id"
36
def _get_price(self, cr, uid, ids, field_name=None, arg=None, context={}):
38
lines=self.browse(cr, uid, ids)
41
res[l.id]=l.quantity * l.product_id.price
47
'product_id': fields.many2one('tiny_purchase.product', 'Product', required=True),
48
'quantity': fields.integer('Quantity'),
49
'price': fields.function(_get_price, method=True, string='Price', type='float'),
50
'comments': fields.text('Comments'),
51
'order_id': fields.many2one('tiny_purchase.order', 'Order', required=True),
55
'quantity': lambda *a: 0,
58
def onchange_compute_price(self, cr, uid, ids, product_id, quantity):
61
price = self.pool.get('tiny_purchase.product').read(cr, uid, [product_id], ['price'])[0]['price']
62
return {'value':{'price': price * quantity,}}