Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to sort report lines in invoices, SO or DO?

By
Tomás Pascual
on 1/20/15, 5:49 AM 1,448 views

Hi Sirs,

I'm trying to sort lines by a field in reports, but in rml i'm unable to get.

Any idea wellcoming,

Regards,

First, the lines will be sorted by the model's _order attribute (which defaults to id) when it is browsed (or SELECT-ed). In order to change that, you need to either do a manual search and specify the order_by parameter or sort the records after the being selected. Maybe you can share the result that you needed and what is the result that you are getting so that we can help you further.

Ivan
on 1/20/15, 6:08 AM
2

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 1/20/15, 6:19 AM

To sort invoice, you need a srto method in your rml parser... 
best way is to make a custom report parser... 
Here is an example parser :
 

class account_invoice(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(account_invoice, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time,
            'sort':self._sort})

    def _sort(self, theList):
        #sorting by name ... change to apropriate: sequence, code price...
        theList.sort(key=lambda x: x.name, reverse=False)
        return theList

 

Now, in your rml you can instead of: [[ repeatIn(o.sort_print,'l') ]]

use :   [[ repeatIn(sort(o.invoice_line),'l') ]]
for reveserse sort order : [[ repeatIn(sort(o.invoice_line, reverse=True),'l') ]]
modifiy sort conditions to your needs...
hope it helps...

Hi sirs, I undestand that must to create a new app, isn't it? I tell you something.

Tomás Pascual
on 1/20/15, 9:06 AM

yes, in order to do this you have to write the code somewhere, so best place is custom module...

Bole
on 1/20/15, 9:10 AM
0
Tomás Pascual
On 1/20/15, 6:16 AM

Hi Ivan,

Thanks for your fast response, it is attached a DO that I want to sort by the 3rd field in column (rack). It seems like always it is sorted by description.

https://docs.google.com/a/onduex.com/file/d/0B0aJ9T6EXAWBeUtfNFRERnQxMnc/edit?usp=drivesdk

Yes, DO lines (stock.move) are sorted by description by default. If you need to change the sort order, first, if the field is a function field or related field, it need to be stored in database. Then, @Bole has provided a very good example of a way to get it sorted without having to change the model's _order attribute (which will change all sorting order in the whole application for stock.move). The x.name in the _sort method should be replaced with the field that you want to sort with. If you want to change the model's sorting order in the whole application (mind you that stock.move is used for Incoming Shipment lines and Internal Move lines aside from Delivery Order lines), then you inherit the model can specify the _order attribute.

Ivan
on 1/20/15, 7:00 AM

Sorry, to complete @Bole's example, the _sort method should accept reverse optional argument and pass it to the sort, i.e. def _sort(self, theList, reverse=False): #sorting by name ... change to apropriate: sequence, code price... theList.sort(key=lambda x: x.name, reverse=reverse) return theList

Ivan
on 1/20/15, 7:02 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/20/15, 5:49 AM
Seen: 1448 times
Last updated: 3/16/15, 8:10 AM