Odoo Help


TypeError: 'int' object has no attribute '__getitem__'

on 9/6/16, 5:43 AM 195 views

my .py file

# -*- coding: utf-8 -*-

from openerp import models, fields, api

from datetime import datetime, timedelta

from dateutil.relativedelta import relativedelta

class FloatingPurchase(models.Model):

    _name= "floating.purchase"

     _inherit = ['mail.thread', 'ir.needaction_mixin']

    _description = "Purchase Order"


        'purchase': [('readonly', True)],

        'done': [('readonly', True)],

        'cancel': [('readonly', True)],


    quantity_no = fields.Integer(string="Quantity", align="center")

     product_id = fields.Many2one('product.template', string ="Product")

     brand_id = fields.Many2one('product.brand', string="Product Brand")

    part_number = fields.Many2one('product.parts', string ="Part Number")

    vendors = fields.Many2one('res.partner', string= "Vendor", required=True)

    store_id = fields.Many2one('res.store', string= "Shop", required=True)

    order_type=fields.Selection([('imp','Import'),('lp','Local Purchase')], string= "Type", required=True)

    date_order = fields.Datetime('Order Date', required=True, select=True)

    product_line = fields.One2many('purchase.product.order.line', 'order_id', string='Order Lines')

    type = fields.Selection([('purchseorder','Purchase Order'),('floating','Floating Purchase Order')], string="Order Type",     required=True)


     def generate_purchase_history(self):

    action = self.env.ref('purchase.action_purchase_line_product_tree')

     domain="[('product_id', '=', self.product_id)]"

    return {

        'name': action.name,

        'help': action.help,

        'type': action.type,

        'view_type': action.view_type,

        'view_mode': action.view_mode,

        'target': action.target,

        'res_model': action.res_model,

        'domain': domain



     def action_purchase_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,

             'date_planned' : self.date_order,

            'order_line' : (6,0, [self.product_line])


    return rec

class PurchaseProductOrder(models.Model):

    _name = "purchase.product.order.line"

    order_id = fields.Many2one('floating.purchase', string='Order Reference', select=True, required=True, ondelete='cascade')

    product_qty = fields.Integer(string="Quantity", align="center")

    product_id = fields.Many2one('product.template', string ="Product")

     product_brand_id = fields.Many2one('product.brand', string="Product Brand")

     product_part_number = fields.Many2one('product.parts', string ="Part Number")

class PurchaseOrderLine(models.Model):

    _inherit = "purchase.order.line"

    #product_qty = fields.Integer(string="Quantity", required=True)

    brand_id = fields.Many2one('product.brand', string="Product Brand", required=True)

    part_number = fields.Many2one('product.parts', string ="Part Number", required=True)

class PurchaseOrder(models.Model):

    _inherit = "purchase.order"

    type = fields.Selection([('purchseorder','Purchase Order'),('floating','Floating Purchase Order')], string="Type")

.xml file

<record id="floating_purchase_order_form" model="ir.ui.view">

    <field name="name">floating.purchase.order</field>

    <field name="model">floating.purchase</field>

    <field name="arch" type="xml">

        <form string="Floating Products">


                <button name="action_purchase_order" string="Add to purchase order" type="object" class="oe_highlight"/>




                    <!-- <field name="brand_id" options='{"no_open": True, "no_create": True}'/>

                    <field name="product_id" domain="[('product_brand_id.id','=',brand_id)]"/>

                    <field name="part_number"/>

                    <field name="quantity_no"/> -->

                    <field name="type" options='{"no_open": True, "no_create": True}'/>

                    <field name="order_type"/>

                    <field name="vendors"/>

                    <field name="store_id"/>

                    <field name="date_order"/>

                    <button name="generate_purchase_history" type="object" string="Product History" />


                <field name="product_line">

                    <tree string="Purchase Order Lines" editable="bottom">

                        <field name="product_brand_id"/>

                        <field name="product_id"/>

                        <field name="product_part_number"/>

                        <field name="product_qty"/>







Divyang Jariwala
On 9/6/16, 7:06 AM

Hi Jithin,


'order_line' : [(6, 0, self.product_line)]

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 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/6/16, 5:43 AM
Seen: 195 times
Last updated: 9/6/16, 7:06 AM