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

Create a res.partner object from a controller

Subscribe

Get notified when there's activity on this post

This question has been flagged
res.partnercontrollersController
1 Reply
6223 Views
Avatar
Blessings

Hello everyone, I'm using Odoo 15 and here's my controller code:


@http.route('/res_partner/create_partner', type='json', auth='none')
    def create_partner(self, json_data):

        vals = ast.literal_eval(json_data)
        admin_id = request.env.ref('base.user_admin')

        vals['company_id'] = admin_id.company_id.id
        vals['user_ids'] = [[6, False, [admin_id.id]]]
        vals['user_id'] = admin_id.id
        vals['is_company'] = False
        # vals['property_account_receivable_id'] = 2  
        # vals['property_account_payable_id'] = 3    
        vals['active'] = False
        vals['type'] = 'contact'
        vals['company_type'] = 'person'

        try:
            new_partner = request.env['res.partner'].sudo().create(vals)
        except Exception as ex:
            logging.warning(ex)
            data = {'response': [], 'message': "Exception occured while creating a partner"}
            return data
       
        else:
            if new_partner:
                data = {'response': [{'id': new_partner.id, 'name' : new_partner.name}], 'message': 'Success'}
            else:
                data = {'response': [], 'message': "Problem occurred with the new partner"}
            return data

Error:

2023-04-20 08:53:21,522 15886 ERROR odoo15_numerp odoo.sql_db: bad query:
                SELECT substr(p.res_id, 13)::integer, r.id
                FROM ir_property p
                LEFT JOIN stock_location r ON substr(p.value_reference, 16)::integer=r.id
                WHERE p.fields_id=3762
                    AND (p.company_id=false OR p.company_id IS NULL)
                    AND (p.res_id IN ('res.partner,56') OR p.res_id IS NULL)
                ORDER BY p.company_id NULLS FIRST
           
ERROR: operator does not exist: integer = boolean
LINE 6:                     AND (p.company_id=false OR p.company_id ...
                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
 
2023-04-20 08:53:21,522 15886 WARNING odoo15_numerp root: operator does not exist: integer = boolean
LINE 6:                     AND (p.company_id=false OR p.company_id ...
                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
 
2023-04-20 08:53:21,523 15886 INFO odoo15_numerp odoo.addons.phone_validation.tools.phone_validation: The `phonenumbers` Python module is not installed, contact numbers will not be verified. Please install the `phonenumbers` Python module.
2023-04-20 08:53:21,525 15886 ERROR odoo15_numerp odoo.sql_db: bad query: SELECT "res_users"."id" as "id", "res_users"."partner_id" as "partner_id", "res_users"."login" as "login", "res_users"."signature" as "signature", "res_users"."active" as "active", "res_users"."action_id" as "action_id", "res_users"."share" as "share", "res_users"."company_id" as "company_id", "res_users"."create_uid" as "create_uid", "res_users"."create_date" as "create_date", "res_users"."write_uid" as "write_uid", "res_users"."write_date" as "write_date", "res_users"."notification_type" as "notification_type", "res_users"."odoobot_state" as "odoobot_state", "res_users"."odoobot_failed" as "odoobot_failed", "res_users"."sale_team_id" as "sale_team_id", "res_users"."oauth_provider_id" as "oauth_provider_id", "res_users"."oauth_uid" as "oauth_uid", "res_users"."oauth_access_token" as "oauth_access_token" FROM "res_users" WHERE "res_users".id IN (1)
ERROR: current transaction is aborted, commands ignored until end of transaction block
 
2023-04-20 08:53:21,525 15886 ERROR odoo15_numerp odoo.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/api.py", line 886, in get
    return field_cache[record._ids[0]]
KeyError: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/fields.py", line 1057, in __get__
    value = env.cache.get(record, self)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/api.py", line 889, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'res.users(1,).partner_id'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
    result = request.dispatch()
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/http.py", line 687, in dispatch
    result = self._call_function(**self.params)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/http.py", line 359, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/http.py", line 355, in checked_call
    self._cr.flush()
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/sql_db.py", line 109, in flush
    self.transaction.flush()
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/api.py", line 833, in flush
    env_to_flush['base'].flush()
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/models.py", line 5644, in flush
    self.recompute()
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/models.py", line 6117, in recompute
    process(field)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/models.py", line 6101, in process
    field.recompute(recs)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/fields.py", line 1243, in recompute
    self.compute_value(recs)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/fields.py", line 1265, in compute_value
    records._compute_field_value(self)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/addons/mail/models/mail_thread.py", line 411, in _compute_field_value
    return super()._compute_field_value(field)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/models.py", line 4255, in _compute_field_value
    getattr(self, field.compute)()
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/addons/base/models/res_partner.py", line 301, in _compute_partner_share
    super_partner = self.env['res.users'].browse(SUPERUSER_ID).partner_id
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/fields.py", line 2603, in __get__
    return super().__get__(records, owner)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/fields.py", line 1083, in __get__
    recs._fetch_field(self)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/models.py", line 3276, in _fetch_field
    self._read(fnames)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/addons/base/models/res_users.py", line 449, in _read
    super(Users, self)._read(fields)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/models.py", line 3343, in _read
    cr.execute(query_str, params + [sub_ids])
  File "", line 2, in execute
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/sql_db.py", line 90, in check
    return f(self, *args, **kwargs)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/sql_db.py", line 313, in execute
    res = self._obj.execute(query, params)
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/http.py", line 643, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/khishgee/Downloads/odoo15/odoo-15.0/NUM_ERP/odoo/http.py", line 301, in _handle_exception
    raise exception.with_traceback(None) from new_cause
psycopg2.errors.InFailedSqlTransaction: current transaction is aborted, commands ignored until end of transaction block

0
Avatar
Discard
Avatar
Blessings
Author Best Answer

It seems that it is impossible to create a res.partner object when there's no session(not logged in). So, I found out that I need to authenticate as a user before calling the res.partner create method.


@http.route('/res_partner/create_partner', type='json', auth='none')
def create_partner(self, json_data):

​test = request.session.authenticate(db="odoo15", login="admin", password="admin")

​session_info = request.env['ir.http'].session_info()

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
Controller giving 404 Error
controllers
Avatar
Avatar
Avatar
2
Aug 25
4777
Controller not working Solved
controllers
Avatar
Avatar
Avatar
2
Jun 25
3063
How to add simple logic inside methods of Odoo 16 website controller?
controllers
Avatar
Avatar
Avatar
3
Jun 24
5647
Domain for res.partner having which are tagged with users ? Solved
res.partner
Avatar
Avatar
2
Oct 23
7459
Restrict duplicate phone number creation in res_partner odoo 16
res.partner
Avatar
Avatar
Avatar
Avatar
3
Sep 23
4270
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