Odoo Help


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

on 9/10/14, 3:01 AM 1,059 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')
                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.



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

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

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

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 :)

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

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)

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