Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Como puedo poner el campo de una relación Many2one es un selection?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
helpodoo
1 Respondre
3080 Vistes
Avatar
Sebastian

Buenos dias, tardes, noches, tengo un problema al intentar poner un campo de la tabla con la que se relacion el One2many. Tengo el siguiente código:


class Item(models.Model):
_name = "sst.item"

cycle_id = fields.Many2one('sst.cycle', string="Ciclo")
standard_id = fields.Many2one('sst.standard', string="Estándar")
substandard_id = fields.Many2one('sst.substandard', string="Subestándar")
literal = fields.Char(string="Literal")
weight = fields.Float(string="Peso")
description = fields.Text(string="Descripción")
legal_frame = fields.Text(string="Marco Legal")
criterion = fields.Text(string="Criterio")
verification = fields.Text(string="Verificación")

plan_evaluation_id = fields.Many2one('sst.initial.evaluation.by.cycles')
do_evaluation_id = fields.Many2one('sst.initial.evaluation.by.cycles')
verify_evaluation_id = fields.Many2one('sst.initial.evaluation.by.cycles')
act_evaluation_id = fields.Many2one('sst.initial.evaluation.by.cycles')

cycle_name = fields.Char(related='cycle_id.cycle', string="Ciclo")
standard_name = fields.Text(related='standard_id.description', string='Estándar')
substandard_name = fields.Text(related='substandard_id.description', string='SubEstándar')

def test(self):
# Buscar si ya existe una evaluación para este ítem y ciclo específico
evaluation = self.env['sst.item.evaluation'].search([
('item_id', '=', self.id),
('evaluation_id', '=', self.plan_evaluation_id.id)
# Filtrar por evaluación del año en curso
], limit=1)

if evaluation:
view_mode = 'form'
res_id = evaluation.id
else:
view_mode = 'form'
res_id = None # No se asigna ID para crear uno nuevo

return {
'type': 'ir.actions.act_window',
'name': 'Evaluación del Ítem',
'res_model': 'sst.item.evaluation',
'view_mode': view_mode,
'view_id': self.env.ref('sst.view_item_evaluation_form').id,
'target': 'new',
'res_id': res_id,
'context': {
'default_item_id': self.id,
'default_evaluation_id': self.plan_evaluation_id.id,
# Establecer el evaluation_id al actual
'default_item_weight': self.weight,
}
}


class ItemEvaluation(models.Model):
_name = "sst.item.evaluation"
_description = "Evaluación del Ítem"

item_id = fields.Many2one('sst.item', string="Ítem")
evaluation_id = fields.Many2one('sst.initial.evaluation.by.cycles', string="Evaluación por Ciclos")
date = fields.Date(string="Fecha", default=fields.Date.context_today)

compliance = fields.Selection(
selection=[],
string="Cumplimiento"
)

applies = fields.Selection([
('aplica', 'Aplica'),
('no_aplica', 'No Aplica')
], string="Aplica", default='aplica')

responsible = fields.Char(string="Responsable")
observation = fields.Text(string="Observación")

De acá lo importante es el modelo

sst.item.evaluation

El cual tiene un campo Many2One con sst.item, y sst.item tiene varios campos entre ellos weight

item_id = fields.Many2one('sst.item', string="Ítem")


Lo que yo deseo hacer es que en el compliance una de las opciones del selection sea el campo weight del modelo sst.item. Quiero hacer algo asi:


compliance = fields.Selection([
('weight', item_id.weight),
​], string="Cumplimiento"
)

​
Pero no he logrado conseguirlo. Me ayudarían mucho, gracias

0
Avatar
Descartar
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,


Using a dynamic value like item_id.weight directly in the Selection field definition isn't possible, as the Selection options are static. However, you can add a related field to get the weight from the related sst.item:

related_item_weight = fields.Float(related='item_id.weight', string="Item Weight")


Keep the compliance field as a Selection field with static options:

compliance = fields.Selection([

    ('weight', 'Weight'),

    ('option1', 'Option 1'),

    ('option2', 'Option 2'),

], string="Cumplimiento")

Add more options as needed instead of option 1 and option 2.


Use a computed field to get the value according to the selected compliance:

compliance_value = fields.Float(string="Compliance Value", compute='_compute_compliance_value', store=True)


@api.depends('compliance', 'related_item_weight')

    def _compute_compliance_value(self):

        for record in self:

            if record.compliance == 'weight':

                record.compliance_value = record.related_item_weight

            else:

                record.compliance_value = 0.0  # or any other default


Also, update your views to include the compliance_value field.


Hope it helps

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

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

Registrar-se
Related Posts Respostes Vistes Activitat
calcule amount_taxed in stock_picking Solved
help odoo
Avatar
Avatar
2
d’abr. 24
2226
ValueError: Compute method failed to assign product.product(627,).alert_tag
help odoo
Avatar
Avatar
1
d’abr. 24
2753
calcule amount_taxed in stock_picking
code help odoo
Avatar
Avatar
Avatar
2
de set. 24
2125
My odoo postgresql database size increased abnormally
help odoo odoo16
Avatar
Avatar
2
de jul. 24
3003
View operation details LImit from 40 TO 100
help odoo 14
Avatar
0
de maig 24
1431
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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