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

How to access a value of a many2one field from a form submitted in openerp?

By
manuthalasseril
on 9/10/14, 3:01 AM 770 views

I have a quotation form with a many2one field (x_delivery_periods) in openerp. Before write to database, I want to calculate the committed date using the function field (commitment_date). So I write the following code.

 

    def _get_commitment_date(self, cr, uid, ids, name, arg, context=None):

            res = {}
            dates_list = []
            deliveryperiod_obj = self.pool.get('stock.deliveryperiods')
            for order in self.browse(cr, uid, ids, context=context):
                dates_list = []

                deliveryperiod_read_test = deliveryperiod_obj.read(cr, uid, 4, ['name'], context) #working
                deliveryperiod_browse_test = deliveryperiod_obj.browse(cr,uid,4).name #working
                print deliveryperiod_read_test #working displays 10.0
                print deliveryperiod_browse_test #working displays {'name': 10.0, 'id': 4}

                print order.x_deliveryperiod #working displays browse_record(stock.deliveryperiods, 4)
                deliveryperiod_read = deliveryperiod_obj.read(cr, uid, order.x_deliveryperiod, ['name'], context) #not working TypeError: argument 2 to map() must support iteration
                deliveryperiod_browse = deliveryperiod_obj.browse(cr,uid,order.x_deliveryperiod).name #not working TypeError: argument 2 to map() must support iteration
                print deliveryperiod_read
                print deliveryperiod_browse

                dt = datetime.strptime(order.date_order, '%Y-%m-%d') + relativedelta(days=deliveryperiod_read or 0.0)
                dt_s = dt.strftime('%Y-%m-%d')
                dates_list.append(dt_s)
                if dates_list:
                    res[order.id] = min(dates_list)
            return res

        _columns = {
            'commitment_date': fields.function(_get_commitment_date, store=True, type='date', string='Commitment Date', help="Committed date for delivery."),
        }

 

But while fetching the data from self.browse oblect results the above errors. Any help will be highly appreciated . Thanks in advance.

1

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 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 9/10/14, 3:11 AM

Hi,

Just make the change as like below.

deliveryperiod_read = deliveryperiod_obj.read(cr, uid, order.x_deliveryperiod.id, ['name'], context)

deliveryperiod_browse = deliveryperiod_obj.browse(cr,uid,order.x_deliveryperiod.id).name

Note : You have to pass "Id" integer value to read and browse method.

Thank you very much chirag. Its working

manuthalasseril
on 9/10/14, 3:21 AM

Your welcome :). When you are able to accept answer then please accept my answer. Thanks for that.

Emipro Technologies Pvt. Ltd.
on 9/10/14, 3:24 AM

Sure my friend..

manuthalasseril
on 9/10/14, 3:25 AM

Hi, Can you accept my answer ?

Emipro Technologies Pvt. Ltd.
on 9/10/14, 8:42 AM

I need 20 karma for accepting the answer. Now I only have 11

manuthalasseril
on 9/11/14, 3:31 AM

Hey ! , You can accept my answer. Awaysome ...

Emipro Technologies Pvt. Ltd.
on 9/11/14, 6:13 AM

yep :)

manuthalasseril
on 9/11/14, 7:07 AM

@chirag Can you check this qtn, please? https://www.odoo.com/forum/help-1/question/how-to-create-a-custom-field-at-delivery-order-stock-picking-out-which-gets-its-value-from-sales-order-in-openerp-62669

manuthalasseril
on 9/14/14, 4:26 AM

Sure, I will look on that question and give you the best answer.

Emipro Technologies Pvt. Ltd.
on 9/15/14, 1:34 AM

Thanks my friend for the helping heart :) (Y)

manuthalasseril
on 9/15/14, 7:31 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: 9/10/14, 3:01 AM
Seen: 770 times
Last updated: 3/16/15, 8:10 AM