Odoo Help

Welcome!

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

0

How to do a one2many view with editable tree? [Closed]

By
Anabela Damas
on 2/21/13, 11:33 AM 9,010 views

The Question has been closed

by
Anabela Damas
on 12/06/2013 11:24:39

Hello, I'm trying to in a form of a sales quotation to show a list of related purchase quotation. And I would like to have a tree like the one in sales order lines where we have the autocomplete to choose the products. But at this moment I have a "Add an item" button that when I click on him it gives me a form to create a new purchase quotation and this new quotation seems to be saved but it isn't saved.

The code to create the relationship: (.../openerp/addons/mymodule.py)

...
class sale_order(osv.osv):
    _inherit = 'sale.order'
    _name = 'sale.order'
    _columns = {
        'asd_squotation': fields.one2many('purchase.order','asd_pquotation_id', 'Purchase Quotation')
    }
sale_order()

class purchase_order(osv.osv):
    _inherit = 'purchase.order'
    _name = 'purchase.order'
    _columns = {
        'asd_currency_id': fields.many2one('res.currency', 'Currency'),
        'asd_msds': fields.boolean('MSDS'),
        'asd_coa': fields.boolean('COA'),
        'asd_pquotation_id': fields.many2one('sale.order','Sale Quotation', domain=[('state','in',('draft','sent'))])
    }
purchase_order()

The code to change the view: (.../openerp/addons/mymodule_view.xml)

<record id="view_mymodule_squotation" model="ir.ui.view">
            <field name="name">mymodule.squotation.inherit</field>
            <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
            <notebook>
                <page string="Purchase Quotation">
                               <field name="asd_squotation" widget="one2many_list" nolabel="1" context="{'asd_pquotation_id':active_id}" class="oe_inline oe_no_button"/>
                </page>
            </notebook>
            </field>
    </record>

What I'm doing wrong?

4

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 3/9/13, 9:59 PM

Hi,

do this :

<record id="view_mymodule_squotation" model="ir.ui.view">
        <field name="name">mymodule.squotation.inherit</field>
        <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="arch" type="xml">
        <notebook>
            <page string="Purchase Quotation">
                           <field name="asd_squotation" widget="one2many_list" nolabel="1" class="oe_inline oe_no_button" context="{'asd_pquotation_id': active_id}"/>
            <tree editable="bottom">
               <field name="asd_pquotation_id" />
               ........
            </tree>
            </page>
        </notebook>
        </field>
</record>

context add in field asd_pquotation in the view is here to fetch the order id value from the parent class to the one2many class, I use active_id for that. in the tree, I add attribute "editable" to have editable lines, value used is "bottom", but you can use "top" too.

in inherited python class purchase_order, add this line :

_defaults = {
    'asd_pquotation_id': lambda self, cr, uid, context: context.get('asd_pquotation_id', False),}

like this, field 'asd_pquotation_id' will be initialized with id value of the order parent class fetch with the context(only if the order form has an id => saved at least one time), if you have not value of the order parent class in the view in this field, the line will not be displayed due to the filter of the one2many.

Bye

Hi,

I tried this solution but I have some errors:

ERROR bionutrigal openerp.osv.orm: Can't find field 'asd_pquotation_id' in the following view parts composing the view of object model 'sale.order': * bionutri.squotation.inherit

ERROR bionutrigal openerp.addons.base.ir.ir_ui_view: Can't render view bionutri.view_bionutri_squotation for model: sale.order

ERROR bionutrigal openerp.tools.convert: Parse error in /opt/openerp-7.0/openerp/addons/bionutri/bionutri_view.xml:75:

ERROR bionutrigal openerp.netsvc: ValidateError Error occurred while validating the field(s) arch: Invalid

Luís
on 3/19/13, 11:27 AM

you known any solution for this errors ??

Thanks.

Luís
on 3/19/13, 11:32 AM

I do an error of copy in code. I corrected my answer too. (confusion between squotation and pquotation). Sorry. Bye

Cyril Gaspard (GEM)
on 3/19/13, 12:13 PM

Hi, with this <field name="asd_pquotation_id" /> I have this: ERROR bionutrigal openerp.osv.orm: Can't find field 'asd_pquotation_id' in the following view parts composing the view of object model 'sale.order':  * bionutri.squotation.inherit ERROR bionutrigal openerp.addons.base.ir.ir_ui_view: Can't render view bionutri.view_bionutri_squotation for model: sale.order

So, I resolve this with <field name="asd_squotation"/> but in sale quotation I have a tab for Purchase Quotation and in this tab I have a list view duplicate one empty and other with information that should have.

Luís
on 3/20/13, 8:45 AM

So to fix this last issue I removed this:

<field name="asd_squotation" widget="one2many_list" nolabel="1" class="oe_inline oe_no_button" context="{'asd_pquotation_id': active_id}"/>

And with this everything seems to be ok.
I hope that you understand what I mean because is difficult to explain without images and characters limited.

Luís
on 3/20/13, 8:56 AM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 2/21/13, 11:33 AM
Seen: 9010 times
Last updated: 3/16/15, 8:10 AM