This question has been flagged
1 Reply
5452 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.

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

Thank you very much chirag. Its working

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

Author

Sure my friend..

Hi, Can you accept my answer ?

Author

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

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

Author

yep :)

Author

@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

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

Author

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