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

overwriting methods create/write with one2many object

Suscribirse

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

Se marcó esta pregunta
many2onecreatev7objectoverwriting
2 Respuestas
11658 Vistas
Avatar
N

In the view of the creation of a sale order, i put a number of section for each sale order line (a section allows me to decompose the sale order into multiple parts). When i create the sale order, i want the sale order section to be created too, with the same number i have put in the view. I've heard about overwriting create/write methods but i don't know how to do. Thanks, here is a part of my code :

class sale_order_line(osv.osv):

_name = 'sale.order.line'
_inherit = 'sale.order.line'

_columns = {
            'section_id': fields.many2one('sale.order.section', 'n° section', required=False, ondelete='cascade', select=True, readonly=True, states={'draft':[('readonly',False)]}),
            'number_section': fields.related('section_id', 'number', type='integer', string='N° section', store=False)
}

class sale_order_section(osv.osv):

_name = 'sale.order.section'
_columns = {
            'order_line': fields.one2many('sale.order.line', 'section_id', 'Order Lines', readonly=False),
            'number': fields.integer('n° section', help='permet de décomposer le devis en sous-sections'),
            'order_id': fields.related('order_line', 'order_id', type="many2one", relation='sale.order', string="Order", readonly=True, required=True),
}
0
Avatar
Descartar
Avatar
ClueLogics Technologies Pvt. Ltd.
Mejor respuesta

Hi n@ilyk

as your Q, you can do like below :

you have inherit sale.order then put these 2 method

def create(self,cr,uid,vals,context=None):

id=super(sale_order,self).create(cr,uid,vals,context)</t>
cid=self.pool.get('sale.order.section').create(cr,uid,{'order_id':id,'number':'sec0001'})
for i in self.browse(cr,uid,id).order_line:

self.poo.get('sale.order.line').write(cr,uid,[i.id],{'section_id':cid})
return id

Thanks

4
Avatar
Descartar
N
Autor

Sorry : where i put this code ? in the sale_order_section class ?

ClueLogics Technologies Pvt. Ltd.

in your inherited sale.order

N
Autor

ok but i don't understand where 'sec0001' come from . In fact, for each order line i have a column "number" where i put the number of section associated to the order line. Also, if i put the same number for 3 order lines for example, just one section has to be created. Thanks for your help

ClueLogics Technologies Pvt. Ltd.

it was just a string which i put it , you can use your own no,,, for number in order line , i think you no need it because you have already a section Id , so why NUMBER ..... even you should use name of filed number as "name" then you can see section number in section Id , then you never need number in order line ,,,, as we have record id

N
Autor

Yes, it is the problem : i try to do 'number': order_line.number but it doesn't work. And a sale order is decomposed into multiples sections and here you create only one section ? I have number because if i write the same number for differents order lines, only one section is created

ClueLogics Technologies Pvt. Ltd.

one sale order as one section Id am i right ??

N
Autor

no : one sale order has multiples sections (a section is a group of invoice lines), that is why i use a number ^^. However, a sale order line is associated with only one section

Avatar
vim24
Mejor respuesta

To override the create method just put your own create method in your sale.order.line class, in the following format:

    def create(self, cr, uid, vals, context=None):
         # Your additional code here
         return super(sale_order_line,self).create(cr,uid,vals,context)

The super(...) will ensure the original create method is still called and creates the object, while you code can add in any additional functionality you need.

0
Avatar
Descartar
¿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
Create new Many2One records in @api.onchange method
many2one create onchange
Avatar
Avatar
1
ago 22
8903
change many2one object field from another object
many2one orm object
Avatar
Avatar
Avatar
5
oct 18
7524
Write method called in the create method
create v7 write
Avatar
Avatar
1
mar 15
8885
Override create on model with no create method?
create v7 inherit
Avatar
Avatar
1
mar 15
7351
many2one link between 2 classes
many2one v7 id
Avatar
Avatar
1
mar 15
5674
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.

Sitio web hecho con

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