Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Integrity Error One2many with Many2one. [Solved]

Subscribe

Get notified when there's activity on this post

This question has been flagged
error
3 Replies
6376 Views
Avatar
Juan Carlos

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:

my.py

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

my.xml

<field name="producto_box">

<tree editable="bottom">

<field name="producto_ids"/>

</tree>

</field>

Image:

https://db.tt/0iKfjOGG

Please help, what is missing?

0
Avatar
Discard
Ivan

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.

Juan Carlos
Author

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.

Ivan

@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.

Juan Carlos
Author

Thanks very much, I edit my answer.

Avatar
Ivan
Best Answer

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

1
Avatar
Discard
Avatar
Juan Carlos
Author Best Answer

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

model.py

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)

#keys
    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")

my.xml

<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">
                    <sheet>
                        <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>
                        
                        <group string="Opciones de Pago">
                            <field name="pago_ids"/>
                            
                        </group>
                        <notebook>
                            <page string="Compras">
                                    <group string="Compras">
                                        <field name="producto_box">
                                            <tree editable="bottom">
                                                <field name="producto_id"/>
                                                <field name="precio"/>
                                            </tree>
                                        </field>
                                        <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"/>
                                        </group>
                                    </group>
                            </page>
                        </notebook>
                    </sheet>
                </form>
            </field>
        </record>

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

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

0
Avatar
Discard
Avatar
Med Said BARA
Best Answer

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

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
?"Your country might be blocked by our hosting provider" error when I create new website
error
Avatar
0
Nov 25
592
Payment Page Return Error with Razorpay on Mobile Devices
error
Avatar
0
Sep 25
1620
Error after installing "purchase" app in Odoo version 18
error
Avatar
Avatar
1
Dec 24
8190
error schema for TourStep Error
error
Avatar
0
Nov 24
3058
Can't modify manifest version of custom module [Odoo.sh]
error
Avatar
Avatar
Avatar
2
Jul 24
5993
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now