This question has been flagged
2 Replies
5109 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"

     READONLY_STATES = {

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

     @api.multi

     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

    }

    @api.multi

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

            <header>

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

            </header>

            <sheet>

                <group>

                    <!-- <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" />

                </group>

                <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"/>

                    </tree>

                 </field>

            </sheet>    

        </form>

    </field>

</record>

Avatar
Discard
Best Answer

Hi , 
in the link : https://odoo-development.readthedocs.io/en/latest/dev/py/x2many.html#x2many-values-filling

you will understand that you need to do the following : 

'order_line' : [(6, 0, self.product_line.ids)]
Avatar
Discard
Best Answer

Hi Jithin,

Try

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

Avatar
Discard