Odoo Help


Integrity Error One2many with Many2one. [Solved]

Juan Carlos
on 12/17/14, 6:57 PM 2,155 views

Ok, i'm trying to create a list of product for a bill. When I save my bill show this error.

Integrity Error

The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set

[object with reference: Product - product.product]

This is my code:


producto_ids = fields.Many2one('product.product', 'Lista de Productos')
producto_box = fields.One2many('openacademy.factura', 'producto_ids', 'Order Lines')


<field name="producto_box">

<tree editable="bottom">

<field name="producto_ids"/>





Please help, what is missing?

If you want to post code, please do it a a more descriptive manner. If the lines you quote in my.py is sequenced exactly like that, no wonder that it would fail. Also, my.xml does not have the context of what model this view is for.

on 12/17/14, 9:21 PM

You're right (sorry for the comment in this, I need 50 karma to comment your answer) I try to obtain products in 'producto_box' but I try to do the same as module 'Sale' in 'Sale Order'. With Many2many I only obtain one product, and I need obtain more products of the same product.

Juan Carlos
on 12/18/14, 10:42 AM

@Juan Many2many allow you to have multiple entries, just like One2many. Many2one only allow you to have one entry. The reason I propose to use Many2many is that you may want to a product to multiple bills as well. If you specify it as One2many, then one product can only be linked to only one bill. @Med Said: it is true that in the official OpenERP most of the many2one fields are named with _id, but the naming for many2many and one2many are more varied: Invoice lines in account.invoice is invoice_line, sale order lines is order_line in sale.order, Physical Inventory lines is inventory_line_id in stock.inventory.

on 12/18/14, 12:05 PM

Thanks very much, I edit my answer.

Juan Carlos
on 12/18/14, 12:42 PM



| 5 3 6
Jakarta, Indonesia
On 12/18/14, 10:19 AM

Why does the bill model (openacademy.factura) has a one2many field to itself using 'product_ids'?  This may be the cause of it.  The producto_box = fields.One2many('openacademy.factura', 'producto_ids', 'Order Lines') should be in product.product model, if I presume it correctly.

Or are you trying to get openacademy.factura to have several products in the producto_box?  If so, you should define producto_box = fields.Many2many('product.product', 'Order Lines') and remove the producto_ids = fields.Many2one('product.product', 'Lista de Productos').

Juan Carlos
On 12/18/14, 10:05 AM

I resolve the problem, thanks Ivan and Med Said, thanks for the help and remind.


class Facturacion(models.Model):
    _name = 'openacademy.factura'

    numeroFactura = fields.Char(string="No. Factura")
    serieFactura = fields.Char(string="Serie")
    fechaFactura = fields.Date(string="Fecha")
    cantidadFactura = fields.Float('Cantidad')
    sin_iva = fields.Integer(string="Sin Iva", readonly=True)
    iva = fields.Integer(string="Con Iva", readonly=True)
    totales = fields.Integer(string="Totales", readonly=True)
    balance = fields.Integer(string="Balance", readonly=True)

    empresa_ids = fields.Many2one('openacademy.empresa', 'Empresa', store=True)
    producto_box = fields.One2many('openacademy.detalle', 'name', 'Order Lines')
    pago_ids = fields.Many2one('openacademy.pago', 'Tipo de Pago', store=True)
    partner_ids = fields.Many2one('res.partner', 'Cliente', store=True)

class DetalleFactura(models.Model):
    _name = "openacademy.detalle"

    name = fields.Char(string="Titulo")
    producto_id = fields.Many2one('product.product', 'Producto')
    precio = fields.Float(string="Precio")


<record model="ir.ui.view" id="facturasform_list">
            <field name="name">Form View</field>
            <field name="model">openacademy.factura</field>
            <field name="arch" type="xml">
                <form string="Factura Form">
                        <group string="Factura">
                            <h2>No.<field name="numeroFactura" class="oe_inline"/></h2>
                            <h2 class="oe_right">Serie<field name="serieFactura" class="oe_inline oe_right"/></h2>
                            <br />
                            <br />
                            <h3 class="oe_left">Nombre de la Empresa:</h3><br />
                            <h3><field name="empresa_ids" class="oe_right"/></h3><h3 class="oe_left">Fecha:   <field name="fechaFactura" class="oe_inline oe_right"/>   </h3>
                            <br />
                            <br />
                            <h3 class="oe_left">Cliente<field name="partner_ids" class="oe_inline" domain="[('customer','=',True)]"/>    </h3><br />
                            <!--<field name="sales_ids"/>-->
                        <group string="Opciones de Pago">
                            <field name="pago_ids"/>
                            <page string="Compras">
                                    <group string="Compras">
                                        <field name="producto_box">
                                            <tree editable="bottom">
                                                <field name="producto_id"/>
                                                <field name="precio"/>
                                        <group class="oe_subtotal_footer">
                                            <field name="sin_iva"/>
                                            <field name="iva"/>
                                            <field name="totales" class="oe_subtotal_footer_separator"/>
                                            <field name="balance" style="margin-top: -5px"/>

I have only been two weeks learning, thank you very much.

Image of results: https://db.tt/7zDYHOfT


Med Said BARA

--Med Said BARA--

| 5 5 7
--Med Said BARA--
Med Said BARA
On 12/18/14, 12:57 PM

In OpenERP: by convention, many2one fields end with '_id' and many2many or one2many end with '_ids'.

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

3 follower(s)


Asked: 12/17/14, 6:57 PM
Seen: 2155 times
Last updated: 3/16/15, 8:10 AM