Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
6301 Widoki

I am trying to print some fields of account.invoice and account.invoice.line

Firstly I added the button for printing csv formatted report.

this is i trying in code


def print_csv(self):      
    lines = []
    lines.append((['Product Name','Price Unit','Quantity']))
    for rec in self.invoice_line_ids:  
      lines.append(([rec.product_id.name,rec.price_unit,rec.quantity]))        
    with open('invoice_details.csv', 'w') as fp:
        a = csv.writer(fp, delimiter=',')            
        data_lines = lines
        a.writerows(data_lines)

the csv file file is downloaded in not browser,it is downloaded in the default location.

How to redirect to the file to download in web browser??

I know this can implemented using controllers in odoo. is there any good example of controller to print csv report??

Awatar
Odrzuć
Najlepsza odpowiedź

Hi acha aslam,

There are various tricks and logic are available to print csv report.

Just refer this link: https://stackoverflow.com/questions/48049787/how-to-print-csv-report-in-browser-odoo

https://www.odoo.com/forum/help-1/question/how-to-export-product-quantities-to-a-csv-file-4104

Accept answer if helpful.

Thank you.

Awatar
Odrzuć
Najlepsza odpowiedź

Hi, here is an example of how I did it using controllers.

Here 'phone.reputation' is a custom model I developed. You can give 'account.invoice', and

give which all fields you want to be printed in the csv file. "name" is the actual field name and "label" is the label how you want that field to have in the csv file. "ids" is the list of ids of records that you want to be printed in the csv  file.

@api.multi
def download_phone_reputation_data(self):
    for intel in self:
        str_dic = """{"model":"phone.reputation",
                            "fields":[{"name":"phone_number","label":"Phone Number"},
                                            {"name":"country_code","label":"Country Code"},
                                            {"name":"country_calling_code","label":"Country Calling Code"},
                                            {"name":"reputation_level","label":"Reputation Level"}, 
                                            {"name":"score","label":"Score"},
                                            {"name":"type","label":"Type"},
                                            {"name":"category","label":"Category"},
                                            {"name":"volume_score","label":"Volume Score"}, 
                                            {"name":"report_count","label":"Report Count"},
                                            {"name":"error","label":"Error"},
                                            {"name":"warnings","label":"Warnings"}],
                                "ids":%s,
                                "domain":[],
                                "context":{},
                                "import_compat":0}""" % intel.phone_reputation_ids.ids
        return {
                'type': 'ir.actions.act_url',
                'url': '/web/export/csv?data=%s&token=' % (str_dic),
                'target': 'current',
                    }


Thanks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
sie 17
6982
2
lip 25
5913
2
paź 25
8504
2
lis 24
29360
2
maj 24
8157