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

All times are UTC + 2 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Override a method problem
PostPosted: Thu May 26, 2011 3:36 pm 
Offline

Joined: Mon Jul 05, 2010 1:54 pm
Posts: 138
Location: Brescia
Hi, I don't know if it's a best practise, but... my need is to give the possibility to aprox manually net price in sale.order (line) so I decide (in my installation ubu 10.4, oerp 6.0.2, sale and sale_layout moudle installed) to override _amount_line method that compute function field price_subtotal value (the one represent in order form in tree view)

sale/sale.py:
Code:
      class sale_order_line(osv.osv):
          def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
              tax_obj = self.pool.get('account.tax')
              cur_obj = self.pool.get('res.currency')
              res = {}
              if context is None:
                  context = {}
              for line in self.browse(cr, uid, ids, context=context):
                  price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
                  taxes = tax_obj.compute_all(cr, uid, line.tax_id, price, line.product_uom_qty, line.order_id.partner_invoice_id.id, line.product_id, line.order_id.partner_id)
                  cur = line.order_id.pricelist_id.currency_id
                  res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])
              return res

sale_layout
Code:
      class sale_order_line(osv.osv)
          def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
              res = {}
              for line in self.browse(cr, uid, ids, context=context):
                  if line.layout_type == 'article':
                      return super(sale_order_line, self)._amount_line(cr, uid, ids, field_name, arg, context)
              return res

my_module:
Code:
      class fiam_sale_order_line_fields(osv.osv):
          def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
              tax_obj = self.pool.get('account.tax')
              cur_obj = self.pool.get('res.currency')
              res = {}
              if context is None:
                  context = {}
              for line in self.browse(cr, uid, ids, context=context):
                 # MODIFIED PART ######################
                  if line.price_use_manual:
                     price = line.price_unit_manual
                  else:     
                     price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
                  #################################
                  taxes = tax_obj.compute_all(cr, uid, line.tax_id, price, line.product_uom_qty, line.order_id.partner_invoice_id.id, line.product_id, line.order_id.partner_id)
                  cur = line.order_id.pricelist_id.currency_id
                  res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])
              return res


I see a problem, with pdb I see that openerp execute only sale.py method instead or my (or sale_layout), so... what's wrong and is that the correct way to modify the "not present" field net price AKA price_subtotal?
Thanks for any clues

_________________
Nico The Brush


Top
 Profile  
 
 Post subject: Re: Override a method problem
PostPosted: Fri May 27, 2011 3:41 am 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
just add the field to your module. An exact copy is fine.

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: Override a method problem
PostPosted: Mon May 30, 2011 10:26 am 
Offline

Joined: Mon Jul 05, 2010 1:54 pm
Posts: 138
Location: Brescia
Thanks gdaddy, I never think about this solution :)
For my test I'm waiting for a bug that I add in lp because, sale_layout has the same problem, its override script is not executed, so original sale.py script is always called...

P.S. I still have problem try to understand what method is called when overrided because, see in this case, there is original sale method, there is sale_layout override + super call and there is mine that override sale... what a confusion :)

_________________
Nico The Brush


Top
 Profile  
 
 Post subject: [solved] Re: Override a method problem
PostPosted: Mon May 30, 2011 3:34 pm 
Offline

Joined: Mon Jul 05, 2010 1:54 pm
Posts: 138
Location: Brescia
As you said, the bug fix is that, the bug I told you previous is fixed with adding the field

http://bazaar.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-788686-psi/revision/4733

Thank you again

_________________
Nico The Brush


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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