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
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
This question has been flagged
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
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
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 | |
|---|---|---|---|---|
|
|
1
Apr 25
|
4847 | ||
|
|
1
Apr 25
|
3203 | ||
|
|
1
Oct 24
|
2552 | ||
|
|
1
Sep 24
|
108 | ||
|
|
0
Mar 24
|
2080 |