コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
6310 ビュー

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

アバター
破棄
関連投稿 返信 ビュー 活動
1
8月 17
6996
2
7月 25
5924
2
10月 25
8515
2
11月 24
29365
2
5月 24
8175