Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

update a fields.many2one openerp

By
namiri
on 5/10/13, 8:25 AM 1,804 views

hi all, i have two objects flot_order_mission and flot_dotation with this implementation:

class flot_order_mission(osv.osv):
    _name = "flot.order"
    _description = "flot_order_Mission"




    _columns = {
                'name': fields.char('Order Reference', size=64, required=True,
            readonly=True, state={'draft': [('readonly', False)]}, select=True),
                'date_order': fields.date('Date', required=True, readonly=True, select=True, state={'draft': [('readonly', False)]}),
                'create_date': fields.datetime('Date Creation', readonly=True, help="La date de la creation de l'ordre de mission"),
                'date_confirm': fields.date('Date Validation', readonly=True, help="La date de la validation de l'ordre de mission"),
                'vers':fields.char('Destination',size=150,help="destination ",required=True),
                'datetimestar':fields.datetime('Date Heure départ',size=10,required=True ,help="La date et l'heure de départ"),
                'datetimeend':fields.datetime('Date Heure Retour',required=True ,help="La date et l'heure de retour"),
                'chauffeur':fields.many2one('flot.chauffeur', 'Chauffeur',required=True),
                'Obj':fields.text('Objet de la mission' ,required=True),
                'carte':fields.many2one('flot.carte', 'carte',required=True),
                'vehicule':fields.many2one('flot.vehicles', 'Vehicule',required=True),
                'user_id': fields.many2one('res.users', 'Editeur', state={'draft': [('readonly', False)]}, select=True),
                'dotation':fields.boolean('avec Dotation',readonly=True,select=True),
                'state': fields.selection([
            ('draft', 'Brouillon'),
            ('cancel', 'Annulé')
            ], 'Etat de l''ordre', readonly=True, help="Etat de l'ordre de mission", select=True),

    }

    _defaults = {
                    'user_id': lambda obj, cr, uid, context: uid,
                    'state': 'draft',
                    'date_order': fields.date.context_today,
                    'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'flot.order'),
                    'dotation' : False
    }   
flot_order_mission()




class flot_dotation(osv.osv):
    _name = "flot.dotation"
    _description = "flot_dotation"
    """
    def write(self, cr, uid, ids, vals, context=None):
        self.pool.get('flot.order').write(cr, uid, 3, {'dotation': True})
        return super(flot_dotation, self).write(cr, uid, id, vals, context=context) 
    """ 
    def write(self, cr, uid, ids, vals, context=None):
        if vals.get('dotation'):
            self.write(cr, uid,vals.get('dotation'),{'custom_field': 'test'},context)
       #if vals.get('dotation'):
         #mydot = self.pool.get('flot.order').browse(cr, uid, vals.get('dotation'), context=context)
        #if mydot.dotation == False:
        #    raise osv.except_osv('Error ! ', "cet order n'est pas dotéé")"""
        return super(flot_dotation, self).write(cr, uid, ids, vals, context)

    _columns = {
                'name': fields.char('dotation Reference', size=64, required=True,
            readonly=True, state={'draft': [('readonly', False)]}, select=True),
                'date_dotation': fields.date('Date', required=True, readonly=True, select=True, state={'draft': [('readonly', False)]}),
                'type_dota':fields.selection([
                        ('in', 'Intrene'),
                        ('out', 'Externe'),
                    ],'Type de la dotation',  help="Type de la dotation",required=True ,select=True),
                'create_date': fields.datetime('Date Creation', readonly=True, help="La date de la creation de l'ordre de mission"),
                'chauffeur':fields.many2one('flot.chauffeur', 'Chauffeur',required=True),
                'date_confirm': fields.date('Date Validation', readonly=True, help="La date de la validation de l'ordre de mission"),
                'order':fields.many2one('flot.order', 'Ordre Mission', domain="[('chauffeur','=',chauffeur),(('dotation','=',False)) ]"),
                'ref':fields.char('Réf Ordre Mission ext', size=64),
                'Obj':fields.text('Objet de la mission' ,required=True),
                'carte':fields.many2one('flot.carte', 'carte',required=True),
                'dotation':fields.float('Dotation',digits=(4,2),required=True),

                'user_id': fields.many2one('res.users', 'Editeur', state={'draft': [('readonly', False)]}, select=True),
                'state': fields.selection([
            ('draft', 'Brouillon'),
            ('donne', 'Valider'),
            ('cancel', 'Annulé')
            ], 'Etat de de la dotation', readonly=True, help="Etat de l'ordre de mission", select=True),

    }

    _defaults = {
                    'user_id': lambda obj, cr, uid, context: uid,
                    'state': 'draft',
                    'date_dotation': fields.date.context_today,
                    'type_dota':'in',
                    'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'flot.dotation'),
    }   
flot_dotation()

when modifying the flot_dotation, i want also update the field dotation in flot_order_mission too.

flot_dotation is related to flot_order_mission by this field 'order':fields.many2one('flot.order', 'Ordre Mission', domain="[('chauffeur','=',chauffeur),(('dotation','=',False)) ]")

can you give me the implementation on write method in the flot_dotation object or a example ?

regards

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 5/10/13, 8:25 AM
Seen: 1804 times
Last updated: 3/16/15, 8:10 AM