İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
6294 Görünümler

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??

Avatar
Vazgeç
En İyi Yanıt

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.

Avatar
Vazgeç
En İyi Yanıt

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

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Ağu 17
6982
2
Tem 25
5909
2
Eki 25
8501
2
Kas 24
29359
2
May 24
8156