Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
9589 Lượt xem

Hi All,

I'm working on module that generates salary report based on a criteria.I have Created a wizard namely my_module_name.wizard, It's of 'models.TransientModel'.My Wizard has a field named file_name i want this field as my xlsx file's name.

I have already tried this , It doesn't work , it always prints the file attribute's value as file name

<report
id="mymodule_xlsx"
model="mymodule.wizard"
string="SIF Report"
report_type="xlsx"
name="mymodule_xlsx.xlsx"    
    file="mymodule_xlsx"   
print_report_name="(object.file_name)"
menu="False"
attachment_use="0"/>

Please Tell me how do we do this?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

modifying the object from python.

@ api.multi

def print_xlsx(self):

    report = self.env ['ir.actions.report'] ._ get_report_from_name ('module.ng_hemployee_xlsx')

     # en v11 ##################

    report.report_file = "new name"

    return self.env.ref ('module.ng_hemployee_xlsx'). report_action (self)

    # en v9 
    report.name = "new name"

    return self.env ['reporte']. get_action (self, 'module.ng_hemployee_xlsx')



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi guys, I solved the problem as follows:
#V12

@api.multi
​def action_print(self): 
    self.env.ref(report_template_xlsx).report_file = "New_name.xlsx"

    return self.env.ref(report_template_xlsx).report_action(self)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

for above you have to override odoo's report method from report  module

Ảnh đại diện
Huỷ bỏ
Tác giả

The report is printing fine.The Problem is with the file Name.

Câu trả lời hay nhất

I have solved it by the following way. Hope it helps

# in your wizard model's action method
report_obj = self.env.ref('module.your_report_id')
report_obj.name = f"your_file_prefix_{self.read()[0].get('your_input_filename')}_postfix.xlsx"

return report_obj.report_action(self, data=data)


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
9
thg 6 23
13050
1
thg 2 23
1752
2
thg 1 22
3860
2
thg 12 21
7881
0
thg 6 21
1931