This question has been flagged
2 Replies
6332 Views

I was trying to create a record with a few required fields in an editable tree view of a one2many field.

If I entered a record correctly and saved it, the creating and saving of the record were always OK.

But, if I accidentally missed one or few required fields when creating a new record, I received warning messages, which was fine to this point. Then, I entered the missed required fields and saved the record. Then, multiple same records (normally the same number of the warning messages) were saved in the tree view, which was definitely wrong, because I only entered one record in the tree view.

I checked the record in the postgresql database. Yes, there were multiple same records. I also traced the create function. of model. Yes, it was called multiple times and each time it added a same record. The problem only occurs within the tree view of a one2many field. No problem with a normal tree view on normal fields.

How could this problem happen? Is there a fix or is it a bug of openerp v7?

======== lgp_testing.py ========

from openerp.osv import osv
from openerp.osv import fields
class lgp_testing(osv.osv):
    _name = 'lgp.testing'
    _description = u'testing'
    _columns = {
        'name': fields.char(u'name', size=60, required=True),
        'detail': fields.one2many('lgp.testingdetails', 'name', u'detail'),
    }
lgp_testing()
class lgp_testingdetails(osv.osv):
    _name = 'lgp.testingdetails'
    _description = u'testingdetails'
    _columns = {
        'name': fields.many2one('lgp.testing', u'name', ondelete='no action'),
        'val': fields.char(u'val', size=100, required=True),
        'date': fields.date(u'date', required=True),
    }
lgp_testingdetails()

======== lgp_testing_view.xml ========


<openerp>
    <data>
        <record model="ir.ui.view" id="view_testing_form">
            <field name="name">testing</field>
            <field name="model">lgp.testing</field>
            <field name="priority" eval="10"/>
            <field name="arch" type="xml">
                <form string="testing">
                    <group colspan="4" col="4">
                        <field name="name" string="name"/>
                    </group>
                    <field name="detail" string="detail" nolabel="1">
                        <tree string="testingdetails" editable="bottom">
                            <field name="val" string="val" required="True"/>
                            <field name="date" string="date" required="True"/>
                        </tree>
                    </field>
                </form>
            </field>
        </record>
        <record model="ir.ui.view" id="view_testing_tree">
            <field name="name">testing</field>
            <field name="model">lgp.testing</field>
            <field name="priority" eval="10"/>
            <field name="arch" type="xml">
                <tree string="testing">
                    <field name="name" string="name"/>
                    <field name="detail" string="detail"/>
                </tree>
            </field>
        </record>
        <record model="ir.actions.act_window" id="action_testing">
            <field name="name">testing</field>
            <field name="res_model">lgp.testing</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="view_testing_tree"/>
        </record>
        <menuitem id="menu_testing" name="testing" parent="menu_settings" action="action_testing" sequence="2"/>
    </data>
</openerp>

Avatar
Discard

Which editable list are you talking about? Not sure that's a Bug.

Author

The editable list is what I created from a one2many field. It appears that the problem does not show in the normal editable list. At least I can repeat the problem in the tree view of one2many fields, but not in a normal tree view.

The only way to deal with your problem, is to begin by posting your code, and if possible to attach some "Print Screen" to illustrate this case

Author

I posted some very simple code that reproduce the errors. How could I post screenshots? My karma is less than 30 now.

Author Best Answer

-- coding: utf-8 --

from openerp.osv import osv

from openerp.osv import fields

class lgp_testing(osv.osv):

_name = 'lgp.testing'

_description = u'testing'

_columns = {

    'name': fields.char(u'name', size=60, required=True),

    'detail': fields.one2many('lgp.testingdetails', 'name', u'detail'),

}

lgp_testing()

class lgp_testingdetails(osv.osv):

_name = 'lgp.testingdetails'

_description = u'testingdetails'

_columns = {

    'name': fields.many2one('lgp.testing', u'name', ondelete='no action'),

    'val': fields.char(u'val', size=100, required=True),

    'date': fields.date(u'date', required=True),
}
Avatar
Discard
Best Answer

Hi andrew try this code it will work correctly,

from openerp.osv import osv
from openerp.osv import fields
class lgp_testing(osv.osv):
    _name = 'lgp.testing'
    _description = 'testing'
    _columns = {
        'name': fields.char('name', size=60, required=True),
        'detail': fields.one2many('lgp.testingdetails', 'name','detail'),
    }
lgp_testing()
class lgp_testingdetails(osv.osv):
    _name = 'lgp.testingdetails'
    _description = 'testingdetails'
    _columns = {
        'name': fields.many2one('lgp.testing','name'),
        'val': fields.char('val', size=100, required=True),
        'date': fields.date('date', required=True),
    }
lgp_testingdetails()
Avatar
Discard
Author

Unfortunately, the code does not work. I opened the form view of lgp.testing and tried to add one record in the tree view of the detail field (one2many). I entered 'val' but left 'date' empty and tried to save a few times. Of course I got a few warning messages for not entering in the required field 'date'. Then, I entered 'date' and saved the record. The problem occurred as a few same records appeared in the tree view. The number of the same records is the same as the number of warning messages. It appears to me that the web cached the non-complete records somehow for saving later.

Author

It does appear to be a bug in openerp web. https://bugs.launchpad.net/openerp-web/+bug/1265705

Author

A solution is posted at the end of the bug link