This question has been flagged
4 Replies
6480 Views

Hello,

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.

Avatar
Discard

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

Author

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

Author

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

Best Answer

Hello,

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.

Avatar
Discard
Author

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

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.