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

Change Odoo invoice payment core behaviour. How to achieve that?

Subscribe

Get notified when there's activity on this post

This question has been flagged
paymentsOdoo12.0
1 Reply
4323 Views
Avatar
Paulo Matos

Hello everyone,

I am having a problem on solving a workflow on Odoo 12 for the invoicing module.

When we pay several invoices on Odoo 12, Odoo sets every selected invoice as paid which is the correct approach.
Problem is that the default order is not the one I need. That is, Odoo pays the invoices starting from the last one (which usually is the newest one) and the oldest one is left for the end.

When the invoices are paid in full, there is no problem, but when the amount to be paid does is not equal to the total value of all selected invoices, the oldest one will be left open.

In my specific case, the order should be changed, that is, oldest invoices should be paid first.

I found that on Odoo core account model we have:
       class AccountInvoice(models.Model):
              _order = "date_invoice desc, number desc, id desc"

I have tested and manually changed this default order to:

      _order = "date_invoice asc, number asc, id asc"

This worked as expected and using this approach, invoices are paid on the desired order.

Since it is not advisable to make direct changes on core odoo modules, I have tried to inherit this class from my module using the following code:

      class AccountInvoice(models.Model):
              _inherit = "account.invoice"
              _order = "date_invoice asc, number asc, id asc"

This change is working because I can see on the invoices list view that the order is changed.

Problem is that even changing the default order, using a custom module, invoice payments are still on the "wrong" order.
So, I get lost here because I was expecting that inheriting the class and changing the order, this will be effective and change core Odoo behaviour.

Can anyone help me change this default order for my specific case?

Thank you all in advance

Best regards

Paulo


1
Avatar
Discard
Avatar
Paresh Wagh
Best Answer

Hi Paulo: It looks like the _order is not driving the order in which the account move lines are getting selected. You may need to extend the following code to force the order in which the payments are reconciled. Hope this helps.

https://github.com/odoo/odoo/blob/12.0/addons/sale/models/account_invoice.py#L66

1
Avatar
Discard
Paulo Matos
Author

Hello @Paresh,

I solved my problem.

In fact was not a problem at all. For some reason the changes I have made where not efective when I inherited the account.invoice model.

After checking everything, not it is woorking as expected.

On my new module I have:

class AccountInvoice(models.Model):

_inherit = "account.invoice"

#_order = "date_invoice desc, number desc, id desc" #This is the default order

_order = "date_invoice asc, number asc, id asc" #New order

On a xml file, in order to get the original Odoo view list:

<record id="sale_tree_view_account_invoice" model="ir.ui.view">

<field name="name">Account Invoice Tree View for Sales</field>

<field name="model">account.invoice</field>

<field name="inherit_id" ref="account.invoice_tree"/>

<field name="arch" type="xml">

<xpath expr="//tree" position="attributes">

<attribute name="default_order">date_invoice desc, number desc, id desc</attribute>

</xpath>

</field>

</record>

...and another record for supplier invoices.

It's working as expected now.

Thank you once again

Best regards

Paulo

Paresh Wagh

Great. So that means the _order is getting used by the move logic too ? Nice find.

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
Custom Dashboard using js
Odoo12.0
Avatar
Avatar
1
Apr 25
4847
When registering payment, i get "can't create a new payment without an outstanding payments/receipts account set"
payments
Avatar
Avatar
1
Apr 25
3203
payments not sorted by date in invoicing
payments
Avatar
Avatar
1
Oct 24
2552
Error reading the payment
payments
Avatar
1
Sep 24
108
How to Limit Pos Category in Odoo 12 Shop?
Odoo12.0
Avatar
0
Mar 24
2080
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