Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
6286 Переглядів

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

Аватар
Відмінити
Найкраща відповідь

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.

Аватар
Відмінити
Найкраща відповідь

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

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
серп. 17
6982
2
лип. 25
5905
2
жовт. 25
8500
2
лист. 24
29357
2
трав. 24
8154