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

error creating and saving records?

By
Andrew Gu
on 4/3/14, 3:41 PM 1,836 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>

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

Med Said BARA
on 4/3/14, 4:09 PM

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.

Andrew Gu
on 4/3/14, 4:28 PM

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

Med Said BARA
on 4/3/14, 4:53 PM

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

Andrew Gu
on 4/3/14, 10:55 PM
0
sridhar
On 4/4/14, 4:05 AM

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

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.

Andrew Gu
on 4/4/14, 12:34 PM

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

Andrew Gu
on 4/4/14, 12:49 PM

A solution is posted at the end of the bug link

Andrew Gu
on 4/4/14, 1:17 PM
0
Andrew Gu
On 4/3/14, 10:28 PM

-- 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),
}

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/3/14, 3:41 PM
Seen: 1836 times
Last updated: 3/16/15, 8:10 AM