openerp-community team mailing list archive
-
openerp-community team
-
Mailing list archive
-
Message #01069
Re: [Openerp-expert-framework] openerp module development issue
client_obj = self.pool.get('client.class')
for client_record in client_obj.browse(cr, uid, ids, context=context):
# One way :
sum_value = sum([ x.duree_taillage for x in client_record.client_id ])
# Other way (better if you have multiple things to sum up)
sum_value = 0
for vignet_record in client_record.client_id:
sum_value += vignet_record.duree_taillage
So you see, the one2many record is actually named a bit wrong, you'd be
better to call it something like
'vigne_ids' because the browse will fill it with a list of browse records
each representing the individual vigne_class.
Hope this helps ?
Drop on by on IRC if you would like to discuss these things more "live"
Regards
Niels 'Red15' Huylebroeck
Agaplan NV
2012/5/24 ange désiré bouabré <angebouabre@xxxxxxxxx>
>
> Excuse me everyone, I develop a module in openerp and I'm stuck in my work
> .I know I'm not allowed to send emails that way but I have no choice. I
> really need your help to continue. It's been a week since I did not
> advance. I just can not help me please:
>
>
> I created 2 objects 'client.class' and 'vigne.class' with one2many and
> many2one fields because one client.class can get one or more vigne.class :
>
>
> *class client_class*(osv.osv) :
>
>
> _name = 'client.class'
>
> _inherit = 'res.partner'
>
> _order ='nom'
>
> _columns = {
>
> *'client_id':fields.one2many('vigne.class','vigne_ids',"Vignes",
> ondelete='set null')*, #'vigne'
>
> 'date':fields.datetime("Date de Creation"),
>
> 'nom': fields.char("Nom et Prenom",size=128),
>
> 'phone': fields.char("Téléphone",size=64),
>
> 'note': fields.text("Note")
>
> ….
>
> ….
>
> ….
>
>
> }
>
>
>
> *class vigne_class*(osv.osv) :
>
>
> _name = 'vigne.class'
>
> _order ='vigne_ids'
>
> def create(self, cr, uid, vals, context={}): ### Fonction pour la
> séquence
>
> vals['ref'] = self.pool.get('ir.sequence').get(cr, uid, 'vigne.class')
>
> res = super(vigne_class, self).create(cr, uid, vals, context)
>
> return res
>
>
> _columns = {
>
> 'date':fields.datetime("Date de Creation"),
>
> *'vigne_ids': fields.many2one('client.class',"Client", readonly=True,
> ondelete='cascade',select=True),*
>
> 'nom': fields.char("Nom de vigne",size=64),
>
> 'guyot':fields.selection([('s','Simple'), ('d','Double')],'Guyot'),
>
> 'lieu': fields.char("Lieu",size=64),
>
> 'nbr_treill': fields.integer("Nombre de treilles")
>
> *'devis_taillage_total'*:
> fields.float("Prix",digits=(10,2),readonly=True),
>
> *'duree_taillage'*:fields.float("Durée du taillage(h)",digits=(10,2))
>
> ….
>
> ….
>
> ….
>
> }
>
>
> I stocked value in fields *'duree_taillage' *and *'devis_taillage_total**
> '** *of* **vigne_class** *and cause some * **client_class* have one or
> many *vigne_class*, i would like to *compute the sum** *of these fields *
> 'duree_taillage'** *and *'**devis_taillage_total'** *for each *
> client_class** *objects created.
>
>
> ex : *client_class_object.**sum_duree_taillage = **vigne_class_1.**duree_taillage+
> **vigne_class_2.**duree_taillage+ **vigne_class_3.**duree_taillage*
>
> and
>
> *client_class_object.**sum_devis_taillage_total = ** **vigne_class_1.**devis_taillage_total+
> **vigne_class_2.**devis_taillage_total+ **vigne_class_3.**
> devis_taillage_total*
>
>
> How browse the *vigne_class* objects of one *client_class* object and get
> these fields to compute them??
>
>
>
>
>
>
>
> There is a complete information in attachment file. PLEASE HELP ME.
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~openerp-expert-framework
> Post to : openerp-expert-framework@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~openerp-expert-framework
> More help : https://help.launchpad.net/ListHelp
>
>
--
Niels Huylebroeck
Lead Architect -- Agaplan
Tel. : +32 (0) 93 95 98 90
Web : http://www.agaplan.eu
References