Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Artificial Intelligence
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

KeyError: 'company_id' after database migration from 16.0 to 17.0 CE (related to Analytic Plans)

Subscribe

Get notified when there's activity on this post

This question has been flagged
salesaccounting
2 Replies
1957 Views
Avatar
Manish Kumar

I just migrated my db from odoo16 to odoo17 community edition

While addling line items in sales documents like sales order or Invoices it's giving the below error

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
  File "/opt/odoo/odoo/odoo/http.py", line 1984, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/odoo/service/model.py", line 152, in retrying
    result = func()
             ^^^^^^
  File "/opt/odoo/odoo/odoo/http.py", line 2012, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/odoo/http.py", line 2216, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/addons/website/models/ir_http.py", line 235, in _dispatch
    response = super()._dispatch(endpoint)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/odoo/addons/base/models/ir_http.py", line 221, in _dispatch
    result = endpoint(**request.params)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/odoo/http.py", line 799, in route_wrapper
    result = endpoint(self, *args, **params_ok)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/addons/web/controllers/dataset.py", line 25, in call_kw
    return self._call_kw(model, method, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/addons/web/controllers/dataset.py", line 21, in _call_kw
    return call_kw(Model, method, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/odoo/api.py", line 480, in call_kw
    result = _call_kw_model(method, model, args, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/odoo/api.py", line 451, in _call_kw_model
    result = method(recs, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/addons/analytic/models/analytic_plan.py", line 212, in get_relevant_plans
    root_plans = (project_plan + other_plans).filtered(lambda p: (
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/odoo/models.py", line 6166, in filtered
    return self.browse([rec.id for rec in self if func(rec)])
                                                  ^^^^^^^^^
  File "/opt/odoo/odoo/addons/analytic/models/analytic_plan.py", line 215, in <lambda>
    and p._get_applicability(**kwargs) != 'unavailable'
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/addons/analytic/models/analytic_plan.py", line 242, in _get_applicability
    for applicability_rule in self.applicability_ids.filtered(
                              ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/odoo/fields.py", line 4471, in __get__
    return super().__get__(records, owner)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/odoo/fields.py", line 2933, in __get__
    return super().__get__(records, owner)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/odoo/fields.py", line 1182, in __get__
    recs._fetch_field(self)
  File "/opt/odoo/odoo/odoo/models.py", line 3824, in _fetch_field
    self.fetch(fnames)
  File "/opt/odoo/odoo/odoo/models.py", line 3863, in fetch
    self.check_access_rule('read')
  File "/opt/odoo/odoo/odoo/models.py", line 4162, in check_access_rule
    invalid = self - self._filter_access_rules_python(operation)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/odoo/models.py", line 4214, in _filter_access_rules_python
    return self.sudo().filtered_domain(dom or [])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/odoo/odoo/models.py", line 6240, in filtered_domain
    field = model._fields[fname]
            ~~~~~~~~~~~~~^^^^^^^
KeyError: 'company_id'

The above server error caused the following client error:
OwlError: An error occured in the owl lifecycle (see this Error's "cause" property)
    Error: An error occured in the owl lifecycle (see this Error's "cause" property)
        at handleError (https://apps.technians.com/web/assets/eea476b/web.assets_web.min.js:938:101)
        at App.handleError (https://apps.technians.com/web/assets/eea476b/web.assets_web.min.js:1596:29)
        at ComponentNode.initiateRender (https://apps.technians.com/web/assets/eea476b/web.assets_web.min.js:1030:19)

Caused by: RPC_ERROR: Odoo Server Error
    RPC_ERROR
        at makeErrorFromResponse (https://apps.technians.com/web/assets/eea476b/web.assets_web.min.js:2956:163)

        at XMLHttpRequest.<anonymous> (https://apps.technians.com/web/assets/eea476b/web.assets_web.min.js:2960:13)

0
Avatar
Discard
Avatar
CandidRoot Solutions
Best Answer
Hey Manish

This issue is caused by incomplete analytic data after migration
from Odoo 16 to Odoo 17.

In Odoo 17, Analytic Plans and their Applicability Rules are
multi-company aware and require a company_id.

During migration, some analytic.plan or analytic applicability
rule records may have company_id set to NULL.
When adding a sales or invoice line, Odoo tries to evaluate
analytic applicability and crashes with:

KeyError: 'company_id'

How to fix:

1) UI-based check (Recommended)
   - Go to Accounting > Configuration > Analytic Plans
   - Open each Analytic Plan
   - Ensure Company is set
   - Check Applicability Rules and assign Company if missing

2) SQL fix (Quick fix – use carefully)
   - Identify analytic plans with company_id IS NULL
   - Assign the correct company_id
   - Restart Odoo service after update

Once all Analytic Plans and related rules have a valid company,
the error disappears.

This is a data consistency issue caused by migration,
not a standard Odoo bug.


After migrating to Odoo 17, analytic plans without company_id cause this error; assigning a company to all analytic plans and rules fixes the issue.

If this helped, kindly upvote.

Best Reagards,


CandidRoot Solutions Pvt. Ltd.
Mobile: (+91) 8849036209
Whatapp: (+91) 8849036209
Email: info@candidroot.com
Web: https://www.candidroot.com
2
Avatar
Discard
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer
Hi,

After migrating from Odoo 16 to Odoo 17 Community, this error is caused by broken analytic plans. Odoo 17 requires analytic plans and their rules to have a company_id, and some migrated records are missing it, triggering the crash when adding sales or invoice lines.

The fix is to ensure all Analytic Plans and Applicability Rules have a company set, or quickly correct them via SQL by assigning a company to plans with company_id = NULL. Once analytics data is fixed, the error disappears.

Hope it helps

-1
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
How can send / receive Peppol Invoices in Odoo? Is it free? Which App / module? Solved
sales accounting
Avatar
Avatar
Avatar
Avatar
Avatar
4
Jun 26
6632
feature request: Structured E-Invoicing (XRechnung / ZUGFeRD / EN 16931) in Odoo Online Free Plan
sales accounting
Avatar
Avatar
1
Feb 26
1862
Warehouse on Product lines level
sales accounting
Avatar
Avatar
Avatar
2
Oct 25
2136
Confusion regarding Product Categories and E-commerce Categories
sales accounting
Avatar
Avatar
Avatar
3
Oct 25
2445
Can I use custom fields and Python to calculate Sales Tax? Solved
sales accounting
Avatar
Avatar
2
Aug 25
2722
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 Svenska ภาษาไทย 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