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
    Real Estate
    • Real Estate Agency
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consulting
    • Accounting Firm
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Furnitures
    • Food
    • 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
    • Solar Energy Systems
    • Shoe Maker
    • Serveis de neteja
    • HVAC Services
    Others
    • 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

How do I load the current data when I opening or clicking on a fields.One2many in odoo.sh 18?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
purchasedevelopment
1 Respondre
1077 Vistes
Avatar
Martin Bando

Hello everyone,


At the moment I can see all the PCs entered in my list, regardless of which customer is selected in the column. However, I would like the PCs to be loaded and displayed only for the selected customers when I click on the x_studio_pc field. How do I do this? Do I have to use OWL? If so, how do I do this? I have no experience with OWL so far.


class ProductTemplate(models.Model):

    _inherit = 'product.template'


    x_studio_pc_liste = fields.One2many('product.template.line', 'x_product_template_id', string='PC Liste')


class ProductTemplateLine(models.Model):

    _name = 'product.template.line'

    _description = 'Product Template Line Modul'

    _order = 'x_product_template_id, x_studio_sequence, id'

    _rec_name = 'x_name'


    x_product_template_id = fields.Many2one('product.template', string='X Product Template', ondelete='cascade')


    x_studio_info = fields.Char(string='Info', default='Please enter the PC in Name', required=True)


    x_studio_sequence = fields.Integer(string='Sequence', default=10)


    x_name = fields.Char(string='Description', required=True)


    x_studio_distribution = fields.Selection(

        [

            ('5575', 'Test1'),

            ('5581', 'Test2'),

            ('5559', 'Test3'),

        ],

        string='Distribution',

        required=True

    )


    x_studio_note = fields.Text(string='Note')


class PurchaseOrderLine(models.Model):

    _inherit = 'purchase.order.line'


    x_studio_pc = fields.Many2one(

        'product.template.line',

        string='PC'

    )


    @api.onchange('product_id')

    def _onchange_product_id_set_pc_domain(self):

        tmpl = self.product_id.product_tmpl_id

       

        if tmpl and hasattr(tmpl, 'x_pc_liste') and tmpl.x_pc_liste:           

            pc_ids = tmpl.x_pc_liste.ids

            return {

                'domain': {

                    'x_studio_pc': [('id', 'in', pc_ids)]

                }

            }

        else:

            return {

                'domain': {

                    'x_studio_pc': []

                }

            }

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

Hi,

Please refer to the code below:


Model: Product template line

- Added new field for customer.

from odoo import models, fields

class ProductTemplateLine(models.Model):
_name = 'product.template.line'
_description = 'Product Template Line Modul'
_order = 'x_product_template_id, x_studio_sequence, id'
_rec_name = 'x_name'

x_product_template_id = fields.Many2one('product.template', string='Product Template', ondelete='cascade')
partner_id = fields.Many2one('res.partner', string='Customer') #ADD THIS LINE
x_studio_info = fields.Char(string='Info', default='Please enter the PC in Name', required=True)
x_studio_sequence = fields.Integer(string='Sequence', default=10)
x_name = fields.Char(string='Description', required=True)
x_studio_distribution = fields.Selection([
('5575', 'Test1'),
('5581', 'Test2'),
('5559', 'Test3'),
], string='Distribution', required=True)
x_studio_note = fields.Text(string='Note')

Model: purchase order line

from odoo import models, fields, api

class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'

x_studio_pc = fields.Many2one('product.template.line', string='PC')

@api.onchange('product_id', 'order_id.partner_id')
def _onchange_product_or_partner(self):
"""
Dynamically filters the available options for the 'x_studio_pc' field
based on the selected product and customer.

Only shows PC entries (product.template.line records) that are linked
to both the selected product template and the selected customer (partner).
If either is not selected, the PC dropdown is emptied.
"""
if self.product_id and self.order_id.partner_id:
tmpl = self.product_id.product_tmpl_id
partner = self.order_id.partner_id
pc_ids = self.env['product.template.line'].search([
('x_product_template_id', '=', tmpl.id),
('partner_id', '=', partner.id)
]).ids
return {'domain': {'x_studio_pc': [('id', 'in', pc_ids)]}}
else:
return {'domain': {'x_studio_pc': []}}

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
How can i change the description of the field 'product_uom' in model 'purchase.order'? Solved
purchase development
Avatar
Avatar
Avatar
2
de jul. 25
1069
Forbidden Opcode in Server Action when Trying to Update Fields in Odoo 16
purchase development accounting
Avatar
Avatar
2
de febr. 25
4258
How to convert or update purchase_double_validation to triple validation in openerp 7?
purchase development validate
Avatar
0
de març 15
4342
How to make all branches for user active automatically after login his account?
development
Avatar
Avatar
1
de nov. 25
184
MrpBom _skip_bom_line skips line of product that has two multi-choice attribute values when both are selected in Apply to variant
development
Avatar
Avatar
1
de nov. 25
171
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