It is currently Tue May 22, 2012 9:42 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Howto inherit/override a method in sales-module
PostPosted: Wed Mar 17, 2010 4:46 pm 
Offline

Joined: Fri Feb 12, 2010 10:57 am
Posts: 68
I'm trying to implement a new method for pricecalculation in the sale_order_line-module.

What is the recommended method for overriding?

class sale_order_line(osv.osv):
_name='sale.order.line'
_inherit='sale.order.line'

# My new pricemethod, same name or new name and changed price_subtotal?
def _amount_line_pm(self, cr, uid, ids, field_name, arg, context):
res = {}
cur_obj = self.pool.get('res.currency')
for line in self.browse(cr, uid, ids):
res[line.id] = my new pricecalcutation
cur = line.order_id.pricelist_id.currency_id
res[line.id] = cur_obj.round(cr, uid, cur, res[line.id])
return res

_columns = {
'pm_length': fields.float('Length'),
'pm_width': fields.float('Width'),
'price_subtotal': fields.function(_amount_line_pm, method=True, string='Subtotal'),
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2010 5:28 pm 
Offline

Joined: Wed Aug 29, 2007 5:45 pm
Posts: 160
Location: Mexico
pricelist in module product is very powerful, what is you need?

excuse me my poor English.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2010 3:51 pm 
Offline

Joined: Fri Feb 12, 2010 10:57 am
Posts: 68
I am aware of the powerful pricelistmodule, but a) I want to control inheritance when i build new modules b) I'm building a pricematrix-module using length and width to find a pricelist. This is useful for a customer that has a large number of variants for each product (ten to twenty variants, all with a new price). Another solution may have been using variants for this.


Top
 Profile  
 
 Post subject: Re: Howto inherit/override a method in sales-module
PostPosted: Thu Oct 14, 2010 8:54 am 
Offline

Joined: Fri Apr 30, 2010 10:35 am
Posts: 90
Hello,

have you found a Solution?
I'm also trying to override a function, but the original one gets called, and the one i created isn't.

so, does anyone please can tell me why or how to do it right?


thanks!


Top
 Profile  
 
 Post subject: Re: Howto inherit/override a method in sales-module
PostPosted: Thu Oct 14, 2010 9:52 am 
Offline

Joined: Sun Dec 28, 2008 1:03 pm
Posts: 190
Location: Genoa
Hi,

in your derived object, just define a method with the same name of the one you want to override.
In the overrided method, if you want to call the ancestor method, use
Code:
super(derived_object, self).method(cr, uid, ...

_________________
Lorenzo Battistini
http://planet.domsense.com/en/author/elbati/
http://www.agilebg.com/


Top
 Profile  
 
 Post subject: Re: Howto inherit/override a method in sales-module
PostPosted: Mon Jan 31, 2011 2:59 pm 
Offline

Joined: Fri Jan 21, 2011 12:36 pm
Posts: 6
Hello,

I'm working with the invoices' creation,

When I call the wizard to create an invoice, the wizard call the function in the module stock.

Now I would like that the wizard call the function in my module.

Code:
class stock_picking(osv.osv):
    _description = "Packing List"
   _table = 'stock_picking'
   _inherit = "stock.picking"

    def action_invoice_create(self, cursor, user, ids, journal_id=False,
            group=False, type='out_invoice', context=None):
        '''Return ids of created invoices for the pickings'''
        invoice_obj = self.pool.get('account.invoice')
        invoice_line_obj = self.pool.get('account.invoice.line')
        invoices_group = {}
        res = {}

.
.
.

stock_picking()


With this code, the wizard don't call my function but the original one.

Thanks


Top
 Profile  
 
 Post subject: Re: Howto inherit/override a method in sales-module
PostPosted: Fri Feb 04, 2011 9:54 pm 
Offline

Joined: Thu Jan 20, 2011 10:48 am
Posts: 5
i have a simular problem, you have install a other modul which overrides the method as well. And this method wins. I dont know if there is a posiblity how to control witch modl wins?


Top
 Profile  
 
 Post subject: Re: Howto inherit/override a method in sales-module
PostPosted: Sat Feb 05, 2011 10:06 pm 
Offline

Joined: Sun Dec 28, 2008 1:03 pm
Posts: 190
Location: Genoa
mschneider wrote:
i have a simular problem, you have install a other modul which overrides the method as well. And this method wins. I dont know if there is a posiblity how to control witch modl wins?

If a module overrides a method and you want to override that method too, simply override the method of the overrider module :lol:

_________________
Lorenzo Battistini
http://planet.domsense.com/en/author/elbati/
http://www.agilebg.com/


Top
 Profile  
 
 Post subject: Re: Howto inherit/override a method in sales-module
PostPosted: Mon Feb 14, 2011 6:14 pm 
Offline

Joined: Thu Jan 20, 2011 10:48 am
Posts: 5
i found the solution, you have to make the other modul requiered by your modul than your function overrides the other.


Top
 Profile  
 
 Post subject: Re: Howto inherit/override a method in sales-module
PostPosted: Sat Jul 30, 2011 10:37 pm 
Offline

Joined: Tue Jan 18, 2011 5:16 pm
Posts: 236
@anders_w

Hi I am trying to make price dependent on with and height, did you manage to do something in that direction?

Thanks,
Mihai

_________________
OpenERP debugging with Eclipse on headless server


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