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

Retrieving a field from self in old API, how does it work?

By
E.M.
on 2/13/16, 6:56 AM 385 views

In sale.py there is the following method:

def _amount_line_tax(self, cr, uid, line, context=None):
val = 0.0
for c in self.pool.get('account.tax').compute_all(cr, uid, line.tax_id, line.price_unit * (1-(line.discount or 0.0)/100.0), line.product_uom_qty, line.product
_id, line.order_id.partner_id)['taxes']:
val += c.get('amount', 0.0)
return val

If I want to retrieve the sale.order name field in this method?

What do I do?

I have tried self.name without success despite print self prints sale.order.


1

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 2/13/16, 7:30 AM

Hello,

It seems that line sent as a browse record; so you can get the order's name as:

order_name = line.order_id.name

Solution from Ahmed is correct. And for your question. self in old api = self.pool['sale.order'] so you need to do a self.browse

Jérémy Kersten (jke)
on 2/13/16, 4:07 PM

Thanks both, it works and now I understand I have to use fields passed explicitly as arguments in the old API. Regarding Jérémy comment, let's see if I was able to understand it right: going with self should be something like: order = self.pool.get('sale.order').browse(cr, uid, line.order_id.id), -as I still need to refer the order's id- and then I could use order.name. Thanks for helping, this post clarifies a lot to me.

E.M.
on 2/14/16, 5:41 AM

Yep, you can access the order as the same as you suggested. You're doing good E.M keep it up :)

Ahmed M.Elmubarak
on 2/14/16, 5:54 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: 2/13/16, 6:56 AM
Seen: 385 times
Last updated: 2/13/16, 4:07 PM