Odoo Help


How to get attribute from another class

on 5/17/16, 6:01 AM 886 views


I've got a little problem. I'm currently creating a custom module on Odoo 9 and I want to get an attribute defined in _columns in an inherit of pos_order in another class inherited : account_invoice.

For this purpose, I declared a variable order as it :

order = self.env['pos.order'].browse(self.reference)

The value I wanna get is the attribute "coupon_nb" from order but the things I tried ("order['coupon_nb'], order[0]['coupon_nb'], order.coupon_nb, order.get('coupon_nb'), ...).

But nothing worked.

Please, help me !

Thank you in advance for your help.

what order gives you ? and what the result of order.coupon_nb ?

Ahmed M.Elmubarak
on 5/17/16, 8:42 AM

When i see the log as a result of "_logger.info("ORDER = %r", order)", we can see "ORDER = pos.order(u'Main/0017',)" and when I do the same thing with "_logger.info("ORDER COUPON = %r", order.coupon_nb)", I got this error : INFO db4 openerp.sql_db: bad query: SELECT "pos_order"."fiscal_position_id" as "fiscal_position_id","pos_order"."id" as "id","pos_order"."state" as "state","pos_order"."create_uid" as "create_uid","pos_order"."pricelist_id" as "pricelist_id","pos_order"."create_date" as "create_date","pos_order"."invoice_id" as "invoice_id","pos_order"."coupon_nb" as "coupon_nb","pos_order"."write_uid" as "write_uid","pos_order"."write_date" as "write_date","pos_order"."account_move" as "account_move","pos_order"."sale_journal" as "sale_journal","pos_order"."loyalty_points" as "loyalty_points","pos_order"."company_id" as "company_id","pos_order"."location_id" as "location_id","pos_order"."session_id" as "session_id","pos_order"."nb_print" as "nb_print","pos_order"."name" as "name","pos_order"."user_id" as "user_id","pos_order"."partner_id" as "partner_id","pos_order"."note" as "note","pos_order"."pos_reference" as "pos_reference","pos_order"."picking_id" as "picking_id","pos_order"."date_order" as "date_order","pos_order"."sequence_number" as "sequence_number" FROM "pos_order" WHERE "pos_order".id IN ('Main/0017') ORDER BY "pos_order"."id" DESC

on 5/17/16, 8:52 AM

(the end of the error :) DataError: invalid input syntax for integer: "Main/0017" LINE 2: WHERE "pos_order".id IN ('Main/0017'...

on 5/17/16, 8:53 AM


You just need to define your order variable is as like below.

order = self[0] #self[zero] means first object from record set.

After assign above value you will get pos.order(10) inside your log when you put this in you logger with the help of  _logger.info("ORDER = %r", order) . Here 10 is ID of that pos.order record.

Note : order = self.env['pos.order'].browse(self.reference) is creating object of pos.order with the help of reference field value "Main/0017", Odoo will treat that value as ID of the record and you will get above error inside your comment.

I hope this will help you to understand.

Thank you. But the problem is that I want to get an object from record set of pos_order from a method of account_invoice. So in account_invoice, I don't get "pos.order(10)" but "account.invoice(10)". My problem is to do the same thing with another class

on 5/19/16, 3:14 AM

Can you paste your code of that account.invoice model ? In which you want to get object/data of pos.order. Will help you exact.

Emipro Technologies Pvt. Ltd.
on 5/20/16, 5:39 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 5/17/16, 6:01 AM
Seen: 886 times
Last updated: 5/19/16, 1:08 AM