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
    • Approvals
    • 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
    • Estate 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

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
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

[Odoo 10] How to correctly call api.onchange?

Subscribe

Get notified when there's activity on this post

This question has been flagged
pythonapionchangeodoo10
4 Replies
22481 Views
Avatar
FEDERICO LEONI

I would like to use api.onchange as a trigger because I don't want to inherit base fields and use api.depends.
A simple example:

class pos_session2(models.Model):
_inherit = 'pos.session'

@api.one #with or without doesn't make any difference
@api.onchange('start_at','stop_at')
def _session_costs_control(self):
_logger.info('Id = %s', self.id)

I get no result (or errors) in log.

How should I call the method?

Edit: Temporary solved creating a  new check field on the same table and calling api.depends.

0
Avatar
Discard
Avatar
Hilar Andikkadavath
Best Answer

Hi,

You dont need to call the method in new api, the method will automatically invokes when any change is acting on 'start_at','stop_at' these fields.

1
Avatar
Discard
FEDERICO LEONI
Author

Problem is the method is not triggered.

In this specific example when I open a new pos session Odoo create the record for 'start_at'. When I close the session Odoo fill with the right datetime the field 'stop_at'.

In both cases _logger.info doesn't show nothing.

Is it possible that onchange is not triggered because it can't see a creation of a new field in a record?

Avatar
Yogesh
Best Answer

did you change 'start_at' and 'stop_at' by hand in browser? it will be invoked only if you change them. 
Note: never use @api.one if you intend to return a value from method because it will wrap the returned value in a list. 

0
Avatar
Discard
FEDERICO LEONI
Author

No, with the new API you don't need to edit the views. From the V10 Docs:

Both computed fields and new-API onchanges are automatically called by the client without having to add them in views.

It is possible to suppress the trigger from a specific field by adding on_change="0" in a view:

<field name="name" on_change="0"/>

will not trigger any interface update when the field is edited by the user, even if there are function fields or explicit onchange depending on that field.

About @api.one, I just tried with and without for a test. I prefer stay with api.depends for now.

FEDERICO LEONI
Author

Link: https://www.odoo.com/documentation/10.0/reference/orm.html

Yogesh

you do not need to add on_change() in xml but you need a field in view. on_cahnge() is triggered at client side. so if there is no change in value on_change will not be called.

FEDERICO LEONI
Author

Understood. Thanks.

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
Error when passing information through API Solved
python api
Avatar
Avatar
1
Sep 23
3177
how to integrate odoo with a website have it's own APIs?
python integration api controller odoo10
Avatar
Avatar
2
Feb 23
11754
onchage function
python onchange
Avatar
Avatar
1
Feb 22
3340
error ConfigParser.ParsingError: File contains parsing errors
python odoo10
Avatar
0
Mar 21
7602
calling api with onchange function
api odoo10
Avatar
0
Sep 20
2698
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 ภาษาไทย 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