It is currently Mon May 21, 2012 6:59 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: how to fill fields automatically!!!!!
PostPosted: Fri Jun 03, 2011 4:21 pm 
Offline

Joined: Tue Mar 29, 2011 5:14 pm
Posts: 14
Hello everyone, i've a problem " how to fill a field automatically ??"
i have three fields Article, Lot and Market in my class , i want that the two fields Lot and Market will be filled automatically when i choose the Article (exactly like when we choose a partner ,his adress is filled automatically).

here is my class that adds those fields to the purchase order line :

Code:
class purchase_order_line(osv.osv):
        _name = "purchase.order.line"
        _inherit = "purchase.order.line"
   _columns = {
         'id_article': fields.many2one('market.articles' , 'Article', required=False),
    'lot_id' : fields.many2one('market.lots', 'Lot Name'),
    'market_id' : fields.many2one('market.articles', 'Market Name'),
     }


and the code of my class Market look like this :
Code:
class market_markets(osv.osv):
   _name = "market.markets"
   _columns = {
      'name' : fields.char('Market Name', size=30, required=True),
      'lot_ids' : fields.one2many('market.lots', 'market_id', 'lot Name'),
              }
market_markets()

class market_lots(osv.osv):
   _name = "market.lots"
   _columns = {
             'name' : fields.char('Lot Name', size=30),
             'article_ids' : fields.one2many('market.articles', 'lot_id', 'Article Name'),
                       }
market_lots()

class market_articles(osv.osv):
      _name = "market.articles"
      _columns = {
      'name' : fields.char('Article Name', size=30, required=True),
               }
market_articles()



Please , any ideas ???????


Top
 Profile  
 
 Post subject: Re: how to fill fields automatically!!!!!
PostPosted: Fri Jun 03, 2011 4:44 pm 
Offline

Joined: Thu May 26, 2011 8:51 pm
Posts: 164
The way to do it is to put one method to be executed in on_change property of the field in the form. Look for it in this page:

http://doc.openerp.com/v6.0/developer/2_6_views_events/views/design_element.html#field

In this method, you can change other form values returning a dictionary with their field names and their values.

Regards.


Top
 Profile  
 
 Post subject: Re: how to fill fields automatically!!!!!
PostPosted: Sun Jun 05, 2011 12:42 pm 
Offline

Joined: Tue Mar 29, 2011 5:14 pm
Posts: 14
hi ,thanks for your answer; i added this class in the py file that contains the class that inherited from purchase_order_line :

Code:
class market_articles(osv.osv):
      def _get_cur_lot_id(self, cr, uid, ids, lot_id, arg, context):
     for i in ids:
         #get the id of the current lot of the article of identifier "i"
         sql_req = """
         SELECT l.id AS lo_id
         FROM purchase_order_line p
           LEFT JOIN market_lots l ON (l.id = p.lot_id)
         WHERE
           (p.id_article = %d)
         """ % (i,)

         cr.execute(sql_req)
         sql_res = cr.dictfetchone()
      
         if sql_res: #The article has one associated lot
             res[i] = sql_res['lo_id']
         else:
             #res[i] must be set to False and not to None because of XML:RPC
             # "cannot marshal None unless allow_none is enabled"
             res[i] = False
     return res

      _name = "market.articles"
      _description = "articles"
      _inherit = "market.articles"
      _columns = {
       'lot_id' : fields.function(_get_cur_lot_id, type='many2one', obj="market.lots", method=True, string="Lot Name"),
      }
       
market_articles()


but it changes nothing :( i don't know what is wrong with the code


Top
 Profile  
 
 Post subject: Re: how to fill fields automatically!!!!!
PostPosted: Mon Jun 06, 2011 3:49 pm 
Offline

Joined: Thu May 26, 2011 8:51 pm
Posts: 164
Well, everything seem to be correct in structure, but maybe the SQL statement is not right (I don't try it). Why don't you use ORM methods instead and quit you to know database internals? This is the document for them: http://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html. They are compact and more intuitive.

Regards.


Top
 Profile  
 
 Post subject: Re: how to fill fields automatically!!!!!
PostPosted: Wed Jun 08, 2011 9:24 pm 
Offline

Joined: Tue Mar 29, 2011 5:14 pm
Posts: 14
hi,
i wanted to define a read function like this:

Code:
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
        if "searched_ids" in context:
            if context["searched_ids"]:
                cr.execute("SELECT id,id FROM table WHERE id_partner = " + str(context["searched_ids"]))
                _ids_filtres_ = dict(cr.fetchall()).keys()
                ids = _ids_filtres_
        return super(ma_classe, self).read(cr, uid, ids, fields, context)


but i still don't understand it very well !

can you provide me some help ? :oops:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP