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

Save record before inverse method

Subscribe

Get notified when there's activity on this post

This question has been flagged
errorcreateinverseodoo16features
1926 Views
Avatar
Clémence Amélineau

Hi,

I'm in odoo v16. In the sale_order_line, I created a field "di_show" to show or not the line in the tree view on the sale_order form

di_show = fields.Boolean('Show line', default=True)

I created 2 one2many field on sale_order and 1 new page with the field "new_line_ids", like the first page with the field "order_line". My one2many new fields had compute and inverse method.

def _compute_new_line_ids(self):
        for sale_order in self:
       
            new_ids = sale_order.order_line.filtered(
                lambda t: t.di_show == True,
                )
       
            sale_order.new_line_ids = [(6,0,new_ids.ids )]
       
            new_ids = sale_order.order_line.filtered(
                lambda t: t.di_show == False,
                )
       
            sale_order.new_line_ids_zero = [(6,0,new_ids.ids )]

new_line_ids = fields.One2many("sale.order.line","id",compute=_compute_new_line_ids,inverse=_inverse_new_line_ids,string="Sale Order Lines")
    new_line_ids_zero = fields.One2many("sale.order.line","id",compute=_compute_new_line_ids,inverse=_inverse_new_line_ids,string="Sale order Lines")

When I change something in my second page, it works great. But when I want to add a line, I have an error because records are not saved before the inverse method. 

I see in debug mode, with expression, my sale_order.new_line_ids contains "line: sale.order.line(477, )" and it's the newId ref who is problematic.

This is my error :

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
  File "C:\Odoo16\server\odoo\http.py", line 1583, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "C:\Odoo16\server\odoo\service\model.py", line 134, in retrying
    result = func()
  File "C:\Odoo16\server\odoo\http.py", line 1610, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "C:\Odoo16\server\odoo\http.py", line 1807, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "C:\Odoo16\server\odoo\addons\base\models\ir_http.py", line 154, in _dispatch
    result = endpoint(**request.params)
  File "C:\Odoo16\server\odoo\http.py", line 696, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "C:\Odoo16\server\odoo\addons\web\controllers\dataset.py", line 42, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "C:\Odoo16\server\odoo\addons\web\controllers\dataset.py", line 33, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "C:\Odoo16\server\odoo\api.py", line 461, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "C:\Odoo16\server\odoo\api.py", line 448, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "C:\Odoo16\server\odoo\addons\sale_stock\models\sale_order.py", line 121, in write
    res = super(SaleOrder, self).write(values)
  File "C:\Odoo16\server\odoo\addons\mail\models\mail_thread.py", line 315, in write
    result = super(MailThread, self).write(values)
  File "C:\Odoo16\server\odoo\addons\mail\models\mail_activity_mixin.py", line 241, in write
    return super(MailActivityMixin, self).write(vals)
  File "C:\Odoo16\server\odoo\models.py", line 3769, in write
    fields[0].determine_inverse(real_recs)
  File "C:\Odoo16\server\odoo\fields.py", line 1377, in determine_inverse
    determine(self.inverse, records)
  File "C:\Odoo16\server\odoo\fields.py", line 100, in determine
    return needle(records, *args)
  File "c:\odoo16\server\odoo\difmiadiv16\batiment\bat_study\models\inh_sale_order.py", line 73, in _inverse_new_line_ids
    sale_order.order_line = [(6,0,sale_order.new_line_ids + sale_order.new_line_ids_zero)]
  File "C:\Odoo16\server\odoo\fields.py", line 1320, in __set__
    records.write({self.name: write_value})
  File "C:\Odoo16\server\odoo\addons\sale_stock\models\sale_order.py", line 121, in write
    res = super(SaleOrder, self).write(values)
  File "C:\Odoo16\server\odoo\addons\mail\models\mail_thread.py", line 315, in write
    result = super(MailThread, self).write(values)
  File "C:\Odoo16\server\odoo\addons\mail\models\mail_activity_mixin.py", line 241, in write
    return super(MailActivityMixin, self).write(vals)
  File "C:\Odoo16\server\odoo\models.py", line 3737, in write
    field.write(self, value)
  File "C:\Odoo16\server\odoo\fields.py", line 4215, in write
    return self.write_batch([(records, value)])
  File "C:\Odoo16\server\odoo\fields.py", line 4236, in write_batch
    return self.write_real(records_commands_list, create)
  File "C:\Odoo16\server\odoo\fields.py", line 4418, in write_real
    unlink(comodel.search(domain))
  File "C:\Odoo16\server\odoo\models.py", line 1509, in search
    return res if count else self.browse(res)
  File "C:\Odoo16\server\odoo\models.py", line 5085, in browse
    if not ids:
  File "C:\Odoo16\server\odoo\tools\query.py", line 217, in __bool__
    return bool(self._result)
  File "C:\Odoo16\server\odoo\tools\func.py", line 28, in __get__
    value = self.fget(obj)
  File "C:\Odoo16\server\odoo\tools\query.py", line 210, in _result
    self._cr.execute(query_str, params)
  File "C:\Odoo16\server\odoo\sql_db.py", line 313, in execute
    res = self._obj.execute(query, params)
  File "C:\Odoo16\python\lib\site-packages\psycopg2\extensions.py", line 121, in getquoted
    pobjs = [adapt(o) for o in self._seq]
  File "C:\Odoo16\python\lib\site-packages\psycopg2\extensions.py", line 121, in
    pobjs = [adapt(o) for o in self._seq]
psycopg2.ProgrammingError: can't adapt type 'sale.order.line'

The above server error caused the following client error:
null

How can I resolve this problem or save / create my value before passing it on to my inverse method ?


Thanks for help

0
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
invf = comodel._fields[self.inverse_name] KeyError: 'move_line_id' "I need help!!! Please"
error odoo16features
Avatar
Avatar
1
Jul 23
5505
module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK' error after installing pdfminer Solved
installation error odoo16features
Avatar
Avatar
Avatar
Avatar
Avatar
4
Jun 25
11623
Error: Field is restricted to the group(s) base.group_no_one in view definition Solved
error view odoo16features
Avatar
Avatar
Avatar
2
Oct 24
10239
Odoo Client Error
error updates odoo16features
Avatar
Avatar
Avatar
2
Sep 24
6792
Odoo 16 white screen/blank page after login Solved
error odoo odoo16features
Avatar
Avatar
2
Mar 24
5154
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