[Openerp-community] openerp module development issue

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[Openerp-community] openerp module development issue

ange désiré bouabré
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.


There is a complete information in attachment file. PLEASE HELP ME.

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp

help_me_please.pdf (439K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

[Openerp-community] openerp module development issue

ange désiré bouabré

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-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp

help_me_please.pdf (439K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] [Openerp-expert-framework] openerp module development issue

Niels Huylebroeck-2
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é <[hidden email]>

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     : [hidden email]
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


_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] [Openerp-expert-framework] openerp module development issue

Olivier Dony (OpenERP)
In reply to this post by ange désiré bouabré
On 05/24/2012 03:56 PM, ange désiré bouabré wrote:
> 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:

You question is perfectly fine for the Community list or on the forum, or via
Launchpad answers, or on IRC (#openobject on Freenode), don't worry :-)
However please don't post such questions on the "openerp-expert-framework"
list, it is meant for advanced questions and framework discussions, not for
simple support.

Concerning your questions, see Niels' answer for an example of the code to
compute the sum. I have some extra minor remarks concerning what you already
wrote, see below, and an example function field that you could add to your
'client' model to show the sum on the Client form.


> 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'
                  ^^^^^
This will not cause problems, but using ".class" suffix for naming your models
is strange and useless. Usually they should be named "module.model", e.g.
"vineyard.vine".


> _inherit = 'res.partner'
>
> _order ='nom'
>
> _columns = {
>
> *'client_id':fields.one2many('vigne.class','vigne_ids',"Vignes", ondelete='set
> null')*, #'vigne'

The names of your one2many field and its reverse many2one relationship are
swapped, which is *very* confusing. Here is how it should be, assuming your
module was named "vineyard":

class client(osv.osv):
    _name = 'vineyard.client'
    _inherit = 'res.partner'
    _columns = {
        'vine_ids': fields.one2many('vineyard.vine', 'client_id', 'Vines'),
    }

class vine(osv.osv):
    _name = 'vineyard.vine'
    _columns = {
        'client_id': fields.many2one('vineyard.client', 'Client'),
    }



> 'date':fields.datetime("Date de Creation"),

You might not need to have an explicit "date" field because all objects have an
implicit "create_date" field by default.


> 'nom': fields.char("Nom et Prenom",size=128),

No need for an extra "nom" field as you inherit from res.partner which has a
'name' field for that same purpose.



> 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??

What you are looking for is a function field, that is a field that is
automatically computed by a python method when you read it.  Using your current
names, you could add a function field on the client.class to compute the sum of
'devis_taillage_total' like this:


class client_class(osv.osv):
    def _compute_taillage(self, cr, uid, ids, field, arg, context=None):
        result = {}
        for client in self.browse(cr, uid, ids, context=context):
            result[client.id] = sum(v.devis_taillage_total
                                        for v in client.client_id)
        return result

    _columns = {
        'devis_taillage_total': fields.function(_compute_taillage,
            type='float', string="Devis Taillage Total')
    }

And if you rename your fields properly as I suggested above, the only thing
that should change in this code is "for v in client.client_id" that will become
a more logical "for v in client.vine_ids"

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] openerp module development issue

ange désiré bouabré
In reply to this post by ange désiré bouabré
Excuse me everyone, please someone could tell me how check field in a object form which is not yet registred??
Cause i want to put "required='1' or required=True" on my one2many field but it does'nt work!!
Help me please!!!
 

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] openerp module development issue

Humberto Arocha

Do that on the xml file for the view of that o2m field

rgrds

Hbto [Vauxoo]

El 14/06/2012 09:13, "ange désiré bouabré" <[hidden email]> escribió:
Excuse me everyone, please someone could tell me how check field in a object form which is not yet registred??
Cause i want to put "required='1' or required=True" on my one2many field but it does'nt work!!
Help me please!!!
 

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp


_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp