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

How to get attribute from another class

By
Matthieu
on 5/17/16, 6:01 AM 447 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.

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

Matthieu
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'...

Matthieu
on 5/17/16, 8:53 AM
0

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5995
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 5/19/16, 1:08 AM

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.

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

Matthieu
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

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: 5/17/16, 6:01 AM
Seen: 447 times
Last updated: 5/19/16, 1:08 AM