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 assign to value from many2one filed to other field (many2one/char)?

Suscribirse

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

Se marcó esta pregunta
many2onevalueassigningv14
2 Respuestas
4237 Vistas
Avatar
Ewdy

I have in res.config .settings field many2one and in account.analytic .line field many2one or char.

I'd like that after set a value in res.config .setting this value assing to field in account.analytic line.

0
Avatar
Descartar
Avatar
Mehjabin Farsana
Mejor respuesta

Hi Ewdy,

If you need to pass the value while creating account.analytic.line you have to pass the value in default_get method of analytic account line model as this:

@api.model
def default_get
(self, fields):
res = super(ProductTemplate, self).default_get(fields)
settings_many2one_field = self.env['ir.config_parameter'].sudo().get_param('settings_many2one_field')
#browse your many2one field id using this settings_many2one_field from your many2one model
    
field_id = self.env['your_model'].search([('id', '=', settings_many2one_field)]).id

    if 'settings_many2one_field' not in fields:
fields.append('settings_many2one_field')
res['many2one_field_analytic_Account'] = field_id.id
return res

Or else you can use compute method for field in analytic account line model

Thank you

2
Avatar
Descartar
Ewdy
Autor

I have a model: MyModel whose inherit from 'account.analytic.line' and another model ResConfigSettings whose inherit from: 'res.config.settings'

In MyModel is first_field(many2one), In ResConfigSettings is second_field(Many2one)
And when wrtie:

@api.model
def default_get(self, fields):
res = super(MyModel, self).default_get(fields)
second_field = self.env['ir.config_parameter'].sudo().get_param('second_field')
if 'second' not in fields:
fields.append('second_field')
res['first'] = second_field.id
return res

I get a error:

res['first_field'] = second_field.id
Exception raise exception.with_traceback(None) from new_cause
AttributeError: 'str' object has no attribute 'id'

In addition, I wonder if it can be done using the method, since the fields are in other models.

Ewdy
Autor

raise exception.with_traceback(None) from new_cause
AttributeError: 'bool' object has no attribute 'id'

# -*- coding: utf-8 -*-
from odoo import models, fields, api

class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
assign_tax = fields.Boolean('Assign Tax Group', default=False, store=True, readonly=False)
tax_group = fields.Many2one('account.account', 'Tax group', readonly=False, store=True)

(other methods)

class TimesheetAccountAssignment(models.Model):
_description = "Timesheet financial account assignment"
_inherit = "account.analytic.line"

general_account_id = fields.Many2one('account.account', string="Accounting account",
compute='_compute_display_name', readonly=False)

@api.model
def default_get(self, fields):
res = super(TimesheetAccountAssignment, self).default_get(fields)
tax_group = self.env['ir.config_parameter'].sudo().get_param('tax_group')
print(tax_group) # it's int (7)
field_id = self.env['account.analytic.line'].search([('id', '=', tax_group)]).id
print(field_id) # return value bool - False
if 'tax_group' not in fields:
fields.append('tax_group')
res['general_account_id'] = field_id.id
return res

Mehjabin Farsana

At first check that record exist or not, later access by id
field_id = self.env['account.analytic.line'].search([('id', '=', tax_group)])
if field_id:
//followed by your code

Ewdy
Autor

Ok, problem was in field_id = self.env['account.analytic.line'].search([('id', '=', tax_group)]),
should be field_id = self.env['account.account'].search([('id', '=', tax_group)]).

Now I have a:
raise exception.with_traceback(None) from new_cause
ValueError: Invalid field 'tax_group' on model 'account.analytic.line'

Avatar
Ewdy
Autor Mejor respuesta
It's work
0
Avatar
Descartar
Mehjabin Farsana

You have to browse the record using the second_field from settings,

Ewdy
Autor

I know, only here in the post I didn't add _field

¿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
Hide some possible choices in a Many2one field
many2one v14
Avatar
Avatar
Avatar
2
abr 23
3583
Odoo 14: How i can set Domain filter on Many2one type field Resuelto
many2one v14
Avatar
Avatar
Avatar
2
feb 25
41902
hide many2one record when changing condition
many2one v14
Avatar
Avatar
Avatar
2
nov 22
3523
Odoo 14: set filter of Many2one field onchange of another Many2one field
many2one v14
Avatar
Avatar
1
feb 22
8508
Many2one field is not showing record name on Saving form Resuelto
many2one v14
Avatar
Avatar
2
dic 21
4940
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