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.

1

Can't override a function field

By
Grover Menacho
on 11/22/13, 10:00 AM 4,678 views

Does anyone know why I can't rewrite the _amount_line method on sale.order.line???

Maybe because it's a private function?

I'm not sure.

This doesn't work alone:

    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.product_id, line.order_id.partner_id)
        cur = line.order_id.pricelist_id.currency_id
        #This gets the delivery_price
        total=0
        for delivery_line in line.delivery_lines:
            total+=delivery_line.delivery_price

        res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])+total
    return res

The only solution that I've found is rewrite the function and create the field again:

_columns = {
    'price_subtotal': fields.function(_amount_line, string='Subtotal', digits_compute= dp.get_precision('Account')),
}

Am I missing something? Or It's something that happens all the time?

Thanks,

Grover Menacho

6

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 11/22/13, 10:42 AM

Yes, it is required to specify the field again.

Another option would be to only update the function pointer:

self._columns['price_subtotal']._fnct = _amount_line

Thanks Andreas Brueckl, that fixed my problem.

ARRIOUACH Mohamed
on 10/30/14, 6:15 AM

Hello. I'd like to know where to put this code... Thank you!

Marie Pinto
on 10/12/15, 7:08 PM
1
igor
On 10/8/14, 4:16 AM

i can't get this to work either... 

if i specify the field again, function is called, but then sale.order module can't acces 'price_subtotal', and i don't see why not...

( File "/opt/openerp/server/openerp/addons/sale/sale.py", line 100, in _amount_all

val1 += line.price_subtotal File "/opt/openerp/server/openerp/osv/orm.py", line 504, in __getattr__ raise AttributeError(e) AttributeError: 857)

i also can't figure out how to update function pointer...

0
Ajay
On 6/6/14, 6:28 AM

Ok. thanks. I didn't know about this and I was breaking my head trying to check this.

Hey Andreas can you tell where to put the line you suggested in code?? I tried before & after the overridden function it gives me error.

Ajay
on 6/6/14, 6:30 AM

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

1 follower(s)

Stats

Asked: 11/22/13, 10:00 AM
Seen: 4678 times
Last updated: 3/16/15, 8:10 AM