Writing elements to one2many from another model?
<p>How can we pass data's to one2many field where my data's are from another model. 
I have written like these but error is showing.</p>

<p>I am accessing these function through button.</p>

<pre><code>@api.multi
    def action_order(self):
rec= self.env['purchase.order'].create({
            'partner_id' : self.vendors.id,
            'store_id' : self.store_id.id,
            'purchase_order_type' : self.order_type,
            'date_order' : self.date_order,
            'date_planned' : self.date_order,
            'type' : self.type,
            'order_line' : (0, 0, [{'brand_id' : self.product_brand_id,
                                    'product_id' : self.purchase_product_id,
                                    'part_number' : self.product_part_number,
                                    'name' : self.desc,
                                    'date_planned' : self.date_order,
                                    'product_qty' : self.quantity_no,
                                    'price_unit' : self.product_price_unit,
                                    'product_uom' : self.product_measure.id,
                                    }])

        })
</code></pre>

<p>My error log is like these</p>

<p>Server Error</p>

<pre><code>Traceback (most recent call last):   File "/opt/ 9/ /openerp/http.py", line 643, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)   File "/opt/ 9/ /openerp/http.py", line 680, in dispatch
    result = self._call_function(**self.params)   File "/opt/ 9/ /openerp/http.py", line 316, in _call_function
    return checked_call(self.db, *args, **kwargs)   File "/opt/ 9/ /openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)   File "/opt/ 9/ /openerp/http.py", line 309, in checked_call
    result = self.endpoint(*a, **kw)   File "/opt/ 9/ /openerp/http.py", line 959, in __call__
    return self.method(*args, **kw)   File "/opt/ 9/ /openerp/http.py", line 509, in response_wrap
    response = f(*args, **kw)   File "/opt/ 9/ /addons/web/controllers/main.py", line 896, in call_button
    action = self._call_kw(model, method, args, {})   File "/opt/ 9/ /addons/web/controllers/main.py", line 884, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)   File "/opt/ 9/ /openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)   File "/opt/ 9/ /openerp/api.py", line 381, in old_api
    result = method(recs, *args, **kwargs)   File "/opt/ 9/custom/trunk/floating_purchase_order/models/floating.py", line 57, in action_purchase_order
    if self.action_order():   File "/opt/ 9/ /openerp/api.py", line 248, in wrapper
    return new_api(self, *args, **kwargs)   File "/opt/ 9/custom/trunk/floating_purchase_order/models/floating.py", line 99, in action_order
    'product_uom' : self.product_measure.id,   File "/opt/ 9/ /openerp/api.py", line 248, in wrapper
    return new_api(self, *args, **kwargs)   File "/opt/ 9/ /addons/purchase/purchase.py", line 180, in create
    return super(PurchaseOrder, self).create(vals)   File "/opt/ 9/ /openerp/api.py", line 248, in wrapper
    return new_api(self, *args, **kwargs)   File "/opt/ 9/ /addons/mail/models/mail_thread.py", line 232, in create
    thread = super(MailThread, self).create(values)   File "/opt/ 9/ /openerp/api.py", line 248, in wrapper
    return new_api(self, *args, **kwargs)   File "/opt/ 9/ /openerp/models.py", line 4151, in create
    record = self.browse(self._create(old_vals))   File "/opt/ 9/ /openerp/api.py", line 248, in wrapper
    return new_api(self, *args, **kwargs)   File "/opt/ 9/ /openerp/api.py", line 490, in new_api
    result = method(self._model, cr, uid, *args, **old_kwargs)   File "/opt/ 9/ /openerp/models.py", line 4336, in _create
    result += self._columns[field].set(cr, self, id_new, field, vals[field], user, rel_context) or []   File "/opt/ 9/ /openerp/osv/fields.py", line 823, in set
    if act[0] == 0: TypeError: 'int' object has no attribute '__getitem__'
</code></pre>

<p>It looks like the the item '<strong>self.product_measure.id</strong>' for '<strong>product_uom</strong>' is creating the problem. It seems it is an 'Integer' field and you are trying to access 'id' out of it.</p>

python openerp