Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Odoo10: Cannot add a record to res.partner using a data file

Naroči se

Get notified when there's activity on this post

This question has been flagged
res.partnerdata.xmlodoo10
1 Odgovori
9294 Prikazi
Avatar
Antonio Miras

I have created a straight forward addon using Odoo bult-in scaffolding tool.

I'm trying to add a record to res.partner using a data file, like this

<odoo>
<data>
<record model="res.partner" id="NewPartner">
<field name="parent_id" eval="ref('base.partner_root')"/>
<field name="name">New Partner</field>
<field name="supplier" eval="True"/>
<field name="employee" eval="False"/>
<field name="is_company" eval="True"/>
<field name="customer" eval="False"/>
<field name="sale_warn">no-message</field>
</record>
</data>
</odoo>

But I keep getting the following error, no matter how I populate "sale_warn"

ParseError: "null value in column "sale_warn" violates not-null constraint

Indeed, sale_warn is a required field, so I need to set a value, but I can't see how.

Furthermore, there are several working AddOns adding records to res.partner without declaring sale_warn field.


 

0
Avatar
Opusti
Avatar
Antonio Miras
Avtor Best Answer

The problem:

My AddOn relies on Sales module.

When Odoo reads my XML data file and tries to insert a new record into res.partner, the model being used is the stock one. To clarify, the one living in “odoo/odoo/addons/base/res/res_partner.py” which doesn't have a sale_warn field.

Now, as Sales module's been installed, the res_partner table in the database already has several required fields found in the inherited ResPartner model. The one in “odoo/addons/sale/models/res_partner.py”

So when the upgrade process is running, no matter whether I use a data file or a Python function, I can't access the fields from the inherited model, but the database runtime is waiting to throw an exception if I don't write those fields.

The solution:

After Odoo is done loading modules, the model res.partner available in the Environment object is the proper one (ResPartner), with all required fields available.

So, in the end, my solution is:

1) Call a python function in my data.xml that will activate a flag, to signal whether my Addon has been installed or upgraded

2) As soon as any part of my AddOn takes over, check the flag, and run an python function to insert default records. A good place to do that might be overriding fields_view_get in any model.

You can also use an additional xml data (not present in manifest.py, obiously), parsed in Python code to insert the data.

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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Extending res.partner - first custom field worked, second raises "ProgrammingError: column ... does not exist" - what did I do wrong? Solved
res.partner odoo10
Avatar
Avatar
Avatar
Avatar
Avatar
8
apr. 23
20105
Is there a differnce? commercial_company_name vs company_name Solved
res.partner odoo10
Avatar
Avatar
2
dec. 16
7315
Mass mailing how to prevent email sending Solved
res.partner mass_mailing odoo10
Avatar
1
jun. 18
4124
I want to hide some res.partner address fields on the website from public visitors. I used a CSV file with READ permissions on res.partner to do this but it isn't working Solved
res.partner website odoo10
Avatar
Avatar
Avatar
Avatar
7
nov. 16
7529
Is there a way to see what causes an Access Error for model operation read? Solved
employee res.partner access_error odoo10
Avatar
Avatar
4
dec. 19
5751
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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