Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

How to create a module that adds records to the database when installed

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
modulesdatabase
2 Respuestas
12881 Vistas
Avatar
Daniele Morelli

Hi, i am using odoo11.

I'd like to make a module that, when installed, simply adds some records to the database. For example, it should add some lines to the res_partner table (the content of those lines would simply be hardcoded in the module itself).

How can I accomplish that? My main problem is that i don't exactly know where to write my code so that it is executed during the installation of the module...

Thanks for any help 

0
Avatar
Descartar
Avatar
Yenthe Van Ginneken (Mainframe Monkey)
Mejor respuesta

Hi Daniele,

You can do this by creating an XML file that contains the data. When you add this XML file to the __manifest__.py file it will be loaded when installing (or updating) the Odoo module. An example of a data record:

<?xml version="1.0" ?>
<odoo>
    <record id="some_record" model="your.model">
        <field name="name">Name of the record</field>
    </record>
</odoo>

You can just load the XML file in the __manifest__ in order to have the data available when installing the app:

# always loaded
    'data': [
        'data/your_data_file.xml',
    ]

You can also find examples of this in the official Odoo code, for example in the app "projects".
Example of data: https://github.com/odoo/odoo/blob/11.0/addons/project/data/project_data.xml  
Example of loading the data: https://github.com/odoo/odoo/blob/e0b1718e4a1ab641f56fef242ae1d6c13254b53c/addons/project/__manifest__.py#L35

Regards,
Yenthe

3
Avatar
Descartar
Daniele Morelli
Autor

Thank you very much for your kind answer!

Yenthe Van Ginneken (Mainframe Monkey)

You're welcome, best of luck!

Avatar
subbarao
Mejor respuesta

Hello Daniele,

By using XML we can do it, see the following example sale order import with two lines while install the module.

<record id="sale_order_1" model="sale.order">

            <field name="partner_id" ref="base.res_partner_2"/>

            <field name="partner_invoice_id" ref="base.res_partner_2"/>

            <field name="partner_shipping_id" ref="base.res_partner_2"/>

            <field name="user_id" ref="base.user_demo"/>

            <field name="pricelist_id" ref="product.list0"/>

            <field name="team_id" ref="sales_team.team_sales_department"/>

            <field name="date_order" eval="(DateTime.today() - relativedelta(months=1)).strftime('%Y-%m-%d %H:%M')"/>

        </record>


        <record id="sale_order_line_1" model="sale.order.line">

            <field name="order_id" ref="sale_order_1"/>

            <field name="name">Laptop E5023</field>

            <field name="product_id" ref="product.product_product_25"/>

            <field name="product_uom_qty">3</field>

            <field name="product_uom" ref="product.product_uom_unit"/>

            <field name="price_unit">2950.00</field>

        </record>


        <record id="sale_order_line_2" model="sale.order.line">

            <field name="order_id" ref="sale_order_1"/>

            <field name="name">Pen drive, 16GB</field>

            <field name="product_id" ref="product.product_product_30"/>

            <field name="product_uom_qty">5</field>

            <field name="product_uom" ref="product.product_uom_unit"/>

            <field name="price_unit">145.00</field>

        </record>

1
Avatar
Descartar
Daniele Morelli
Autor

Thanks!

¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
Uninstall a module without losing info in the DB
modules database uninstall
Avatar
Avatar
1
mar 15
9309
how to get rid of test data without loosing installed Modules?
modules database data
Avatar
Avatar
1
mar 15
5485
Nuevo menú en "CRM"
modules
Avatar
Avatar
Avatar
Avatar
3
jul 25
2768
Allow Access to update module
modules
Avatar
Avatar
Avatar
Avatar
3
may 25
4642
Database disappeared from list after activating Google Oauth for administrator
database
Avatar
0
jul 25
2288
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

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