~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to tiny_purchase/tiny_purchase.py.5

bugfix in overlay creation system

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
from osv import osv
3
 
from osv import fields
4
 
import time
5
 
 
6
 
 
7
 
class product(osv.osv):
8
 
        _name = "tiny_purchase.product"
9
 
        _columns = {
10
 
                'name': fields.char('Name', size=64),
11
 
                'price': fields.float('Price'),
12
 
        }
13
 
product()
14
 
 
15
 
class order(osv.osv):
16
 
        _name = "tiny_purchase.order"
17
 
 
18
 
        _columns = {
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'),
23
 
        }
24
 
 
25
 
        _defaults = {
26
 
                'name': lambda *a: time.strftime('%Y-%m-%d'),
27
 
                'user_id': lambda self, cr, uid, context: uid,
28
 
                'state': lambda *a: 'draft',
29
 
        }
30
 
order()
31
 
 
32
 
class line(osv.osv):
33
 
        _name = "tiny_purchase.line"
34
 
        _rec_name = "product_id"
35
 
 
36
 
        def _get_price(self, cr, uid, ids, field_name=None, arg=None, context={}):
37
 
                res={}
38
 
                lines=self.browse(cr, uid, ids)
39
 
                for l in lines:
40
 
                        if l.product_id:
41
 
                                res[l.id]=l.quantity * l.product_id.price
42
 
                        else:
43
 
                                res[l.id]=0
44
 
                return res
45
 
 
46
 
        _columns = {
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),
52
 
        }
53
 
 
54
 
        _defaults = {
55
 
                'quantity': lambda *a: 0,
56
 
        }
57
 
 
58
 
        def onchange_compute_price(self, cr, uid, ids, product_id, quantity):
59
 
                if not product_id:
60
 
                        return {}
61
 
                price = self.pool.get('tiny_purchase.product').read(cr, uid, [product_id], ['price'])[0]['price']
62
 
                return {'value':{'price': price * quantity,}}
63
 
line()