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
    • Estate 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

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
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

one2many field is not showing after created at new model

Subscribe

Get notified when there's activity on this post

This question has been flagged
one2manyrelationfield
5454 Views
Avatar
Gamey Garcia Varela

Hello, I'm developing a module to take the control of a touristic transportation company what do is make an order service of tours for people taking the data from sale.order.lines (the previously sold tours) and with this info I take the vehicle and operator from Fleet module, and with all this data make the service page. 

The problem is after I saved the data I took from sale.order.lines, it saves the data at the table I created but the model don't show it at the view.

This is the code:

----PYTHON file:

# -*- coding: utf-8 -*-

# Part of Odoo. See LICENSE file for full copyright and licensing details.

from openerp import models, fields, api


class ServicesPage(models.Model):

_name = 'services.page'


name = fields.Char('Referencia Hojas Servicios', readonly=True)

fecha_tour = fields.Date('Fecha de Servicio')

page_lines_id = fields.One2many('page.lines', 'service_page_id', string='Líneas de Servicio',copy = True) 


@api.model

def create(self, vals):

vals['name'] = self.env['ir.sequence'].get('services.page')

return super(ServicesPage, self).create(vals)


@api.multi

def write(self, vals):      

result = super(ServicesPage, self).write(vals)

return result


class PageLines(models.Model):

_name = 'page.lines'


name = fields.Char('Referencia Línea de Hoja', readonly=True)

product_id = fields.Many2one('product.product', string = "Servicios")

camioneta = fields.Many2one('fleet.vehicle', string='Camioneta')

chofer = fields.Many2one('res.partner', string='Operador')

combustible = fields.Float('Combustible')

entradas = fields.Float('Entradas')

estacionamiento = fields.Float('Estacionamiento')

casetas = fields.Float('Casetas')

viaticos = fields.Float('Viáticos')

derecho_piso = fields.Float('Derecho Piso')

guia = fields.Float('Guía')

otros = fields.Float('Otros')

service_page_id = fields.Many2one('services.page', 'Service Page Reference',index=True, copy=False)


service_lines_ids = fields.One2many('services.lines', 'page_line_id', string='Líneas de Servicio', copy = True) 


@api.model

def create(self, vals):

vals['name'] = self.env['ir.sequence'].next_by_code('page.lines')    

return super(PageLines, self).create(vals)


@api.multi

def write(self, vals):        

result = super(PageLines, self).write(values)

return result


class ServicesLines(models.Model):

_name = 'services.lines'


name = fields.Char('Referencia Línea de Servicio',readonly=True)


page_line_id = fields.Many2one('page.lines', 'Page Reference',index=True, copy=False)

service_id = fields.Many2one('sale.order.line', string='Servicios Confirmados')

pax = fields.Integer('No. Personas')

pax_asignado = fields.Integer('Cantidad Personas Asignadas')


@api.model

def create(self, vals):

vals['name'] = self.env['ir.sequence'].next_by_code('services.lines')    

return super(ServicesLines, self).create(vals)


@api.multi

def write(self, vals):        

result = super(ServicesLines, self).write(values)

return result


----- XML FILE:


<openerp>

  <data>


    <record id="view_service_page_tree" model="ir.ui.view">

            <field name="name">services.page.tree</field>

            <field name="model">services.page</field>

            <field name="arch" type="xml">

                <tree string="Hojas de Servicios">

                    <field name ="name"/>

                    <field name ="fecha_tour"/>

                </tree>

            </field>

    </record>



    <record id = "view_form_service_page" model = "ir.ui.view">

      <field name="name">view_form_create_service_page_ui</field>

      <field name="model">services.page</field>

      <field name="arch" type="xml">

         <form string="Hojas de Servicios">            

            <sheet>                

                <div class="oe_title">

                    <h1>

                        <field name="name" readonly="1"/>

                    </h1>

                </div>              

                <group>  

                    <field name="fecha_tour"/> 

                </group>

                <notebook>

                    <page string="Hojas de Servicios">

                        <field name="page_lines_id" mode="tree">

                            <form string="Líneas de Hojas de Servicios">

                                <group>

                                    <field name="product_id"/>                               

                                    <field name="chofer"/>

                                    <field name="camioneta"/>                                

                                    <field name="combustible"  widget="monetary"/>

                                    <field name="entradas"  widget="monetary"/>

                                    <field name="estacionamiento"  widget="monetary"/>

                                    <field name="casetas"  widget="monetary"/>

                                    <field name="viaticos"  widget="monetary"/>

                                    <field name="derecho_piso"  widget="monetary"/>

                                    <field name="guia"  widget="monetary"/>

                                    <field name="otros"  widget="monetary"/>

                                </group>    

                                <notebook>

                                    <page string="Lineas de Servicios">

                                        <field name="service_lines_ids" mode="tree">

                                            <form string="Líneas de Servicios">

                                                <group>

                                                    <field name="service_id"/>

                                                    <field name="pax"/>                               

                                                    <field name="pax_asignado"/>

                                                </group>                              

                                            </form>

                                            <tree>      

                                                <field name="service_id"/>

                                                <field name="pax"/>                               

                                                <field name="pax_asignado"/>

                                            </tree>                                                                                   

                                        </field> 

                                    </page>                    

                                </notebook>                         

                            </form>

                            <tree>                                

                                <field name="product_id"/>                               

                                <field name="chofer"/>

                                <field name="camioneta"/>                                

                                <field name="combustible"  widget="monetary"/>

                                <field name="entradas"  widget="monetary"/>

                                <field name="estacionamiento"  widget="monetary"/>

                                <field name="casetas"  widget="monetary"/>

                                <field name="viaticos"  widget="monetary"/>

                                <field name="derecho_piso"  widget="monetary"/>

                                <field name="guia"  widget="monetary"/>

                                <field name="otros"  widget="monetary"/>

                            </tree>                                                                                   

                        </field>                        

                    </page>                    

                </notebook>

            </sheet>            

        </form>          

      </field>

    </record> 

    <record id="view_pages_lines_tree" model="ir.ui.view">

            <field name="name">page.lines.tree</field>

            <field name="model">page.lines</field>

            <field name="arch" type="xml">

                <tree string="Líneas de Páginas">

                    <field name="product_id"/>                               

                    <field name="chofer"/>

                    <field name="camioneta"/>                                

                    <field name="combustible"  widget="monetary"/>

                    <field name="entradas"  widget="monetary"/>

                    <field name="estacionamiento"  widget="monetary"/>

                    <field name="casetas"  widget="monetary"/>

                    <field name="viaticos"  widget="monetary"/>

                    <field name="derecho_piso"  widget="monetary"/>

                    <field name="guia"  widget="monetary"/>

                    <field name="otros"  widget="monetary"/>

                </tree>

            </field>

        </record>


    


    <record id="action_service_page" model="ir.actions.act_window">

      <field name="name">Hojas de Servicios</field>

      <field name="res_model">services.page</field>

      <field name="view_type">form</field>

      <field name="view_mode">tree,form</field>     

    </record>


    <menuitem id="menu_fleet_service_page"

          name="Hoja de Servicios"

          parent="fleet.menu_fleet_reporting"

          action="action_service_page"

          sequence="3"

          />  

  </data>

</openerp>

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
Failing to write Many2one field Solved
one2many create relationfield
Avatar
Avatar
1
Feb 19
4565
Why to add Many2One field on both models?
many2one one2many relationfield
Avatar
Avatar
1
Jan 19
10593
how pass value to on2many field from parent form via context
one2many
Avatar
Avatar
1
Jan 25
2786
How to make tree view place last entered field on the top of tree view? What is the difference between editable="top" and editable="bottom"?
one2many
Avatar
Avatar
Avatar
2
Sep 22
10513
How to configure one2many field inside a form with domain or filter Solved
one2many
Avatar
Avatar
2
Apr 22
5340
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 ภาษาไทย 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