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

How to add a new Many2one field in res.config.settings?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
v17
4 Respostes
3626 Vistes
Avatar
Daniel Bashev

​I am working on an app where I need to set a default pricelist, based on whether the res.partner (Contact) is an individual or a company. This needs to be a field in the settings tab, so that the user can select which pricelist to use for company and which one for individuals. I managed to get this field to show up with this model:
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

​ default_pricelist_company = fields.Many2one(
        ​ ​'product.pricelist',
        ​ ​string="Default Pricelist for Companies",
        ​ ​default_model='res.partner',
        ​ ​config_parameter='my_addon.default_pricelist_company'
​) 
default_pricelist_individual = fields.Many2one(
        ​ ​'product.pricelist',
        ​ string="Default Pricelist for Individuals",
        ​ ​default_model='res.partner',
        ​ config_parameter='my_addon.default_pricelist_individual' 
​)

However, this causes an error on save, that the field res.partner.pricelist_company does not exist.
I am relatively new to odoo so I am not sure exactly what i am doing wrong or how to properly set up these settings. Any help, or explanation of what i am doing wrong is highly appreciated, thanks!

0
Avatar
Descartar
Daniel Bashev
Autor

I tried removing the default_model, but then I ran into this error:

File "/home/linuxsub/odoo/odoo/odoo/addons/base/models/res_config.py", line 427, in _get_classified_fields
raise Exception("Field %s without attribute 'default_model'" % field)
Exception: Field res.config.settings.default_pricelist_company without attribute 'default_model'

Avatar
Mehjabin Farsana
Best Answer

Hi,

The default_model argument is unnecessary here, as the settings are stored in the system parameter, not directly on the res.partner model. so default_model should be removed

Hope this will help you

thanks


0
Avatar
Descartar
Avatar
Daniel Bashev
Autor Best Answer

The problem I was encountering was because my variables started with "default_", changing them resolved the issue in my case.

2
Avatar
Descartar
Avatar
Rani Tathod
Best Answer

Hello Daniel, I'll help you set up the Many2one fields in res.config.settings correctly.



  The error occurs because Odoo attempts to write the value of default_pricelist_company and default_pricelist_individual directly to a field named pricelist_company and pricelist_individual on the res.partner model, which do not exist.

  Remove the default_model='res.partner' from your field definitions. This attribute is not needed and causes Odoo to look for corresponding fields on res.partner.

  Instead of relying on default_model, you will need to create a function that applies the pricelist based on the configuration when a partner is created or updated. This can be achieved by inheriting the create and write methods of res.partner.

  Here's an example of how you might structure your res.config.settings model:
  ```python
  class ResConfigSettings(models.TransientModel):
    _inherit = 'res.config.settings'

    default_pricelist_company = fields.Many2one(
        'product.pricelist',
        string="Default Pricelist for Companies",
        config_parameter='my_addon.default_pricelist_company'
    )
    default_pricelist_individual = fields.Many2one(
        'product.pricelist',
        string="Default Pricelist for Individuals",
        config_parameter='my_addon.default_pricelist_individual'
    )
  ```

  Then, in your res.partner model, override the create and write methods to apply the pricelists:
  ```python
  class ResPartner(models.Model):
    _inherit = 'res.partner'

    @api.model
    def create(self, vals):
        partner = super(ResPartner, self).create(vals)
        self._set_default_pricelist(partner)
     &

1
Avatar
Descartar
Avatar
Nguyễn Hữu Phước
Best Answer

Change your field  name from default_pricelist_company to pricelist_company_default

Because if you set the first name of your field name by default, it will raise this error


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
Ya es posible hacer Upgrade de v17 a v17.1 ?
v17
Avatar
Avatar
1
d’oct. 25
1265
Add field to ALL models in Odoo
v17
Avatar
Avatar
Avatar
2
de set. 25
2295
How to disable Email notification - You have been assigned to Solved
v17
Avatar
Avatar
Avatar
Avatar
4
de set. 25
7655
Selection Field Options Disappear from Database (PostgreSQL enum) on Module Upgrade
v17
Avatar
0
d’ag. 25
1219
How to get the active_id from get_view function in odoo 17?
v17
Avatar
Avatar
Avatar
Avatar
Avatar
4
de maig 25
4435
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