'name':fields.char('Name',size=64,required=True,help='The name of the segmentation.'),
'description':fields.text('Description'),
'categ_id':fields.many2one('res.partner.category','Partner Category',required=True,help='The partner category that will be added to partners that match the segmentation criterions after computation.'),
'exclusif':fields.boolean('Exclusive',help='Check if the category is limited to partners that match the segmentation criterions. If checked, remove the category from partners that doesn\'t match segmentation criterions'),
'som_interval':fields.integer('Days per Periode',help="A period is the average number of days between two cycle of sale or purchase for this segmentation. It's mainly used to detect if a partner has not purchased or buy for a too long time, so we suppose that his state of mind has decreased because he probably bought goods to another supplier. Use this functionnality for recurring businesses."),
'som_interval_max':fields.integer('Max Interval',help="The computation is made on all events that occured during this interval, the past X periods."),
'som_interval_decrease':fields.float('Decrease (0>1)',help="If the partner has not purchased (or buied) during a period, decrease the state of mind by this factor. It\'s a multiplication"),
'som_interval_default':fields.float('Default (0=None)',help="Default state of mind for period preceeding the 'Max Interval' computation. This is the starting state of mind by default if the partner has no event."),
'sales_purchase_active':fields.boolean('Use The Sales Purchase Rules',help='Check if you want to use this tab as part of the segmentation rule. If not checked, the criteria beneath will be ignored')
cr.execute('select sum(l.price_unit*l.quantity) from account_invoice_line l left join account_invoice i on (l.invoice_id=i.id) where i.partner_id=%d',(partner_id,))
value=cr.fetchone()[0]or0.0
elifl['expr_name']=='purchase':
cr.execute('select sum(l.price_unit*l.quantity) from account_invoice_line l left join account_invoice i on (l.invoice_id=i.id) where i.partner_id=%d',(partner_id,))