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

« back to all changes in this revision

Viewing changes to tiny_purchase/tiny_purchase.py.2

  • Committer: ced
  • Date: 2007-03-30 12:31:07 UTC
  • Revision ID: ced-6c295a7c19ba0a3c2154f68429d6159d83f9bc15
TINY_PURCHASE: add new module, with 4 exercices

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 line(osv.osv):
 
16
        _name = "tiny_purchase.line"
 
17
 
 
18
        def _get_price(self, cr, uid, ids, field_name=None, arg=None, context={}):
 
19
                res={}
 
20
                lines=self.browse(cr, uid, ids)
 
21
                for l in lines:
 
22
                        if l.product_id:
 
23
                                res[l.id]=l.quantity * l.product_id.price
 
24
                        else:
 
25
                                res[l.id]=0
 
26
                return res
 
27
 
 
28
        _columns = {
 
29
                'name': fields.date('Date'),
 
30
                'user_id': fields.many2one('res.users', 'User', required=True),
 
31
                'product_id': fields.many2one('tiny_purchase.product', 'Product', required=True),
 
32
                'quantity': fields.integer('Quantity'),
 
33
                'price': fields.function(_get_price, method=True, string='Price', type='float'),
 
34
                'comments': fields.text('Comments'),
 
35
        }
 
36
 
 
37
        _defaults = {
 
38
                'name': lambda *a: time.strftime('%Y-%m-%d'),
 
39
                'user_id': lambda self, cr, uid, context: uid,
 
40
                'quantity': lambda *a: 0,
 
41
        }
 
42
line()
 
43