Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
26834 Lượt xem
I'm trying hide two reports, but when i run the code only one (first report) is not displayed. Can you tell me what the problem is?     
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(AccountInvoice, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu)
report_account_invoice_bill = self.env.ref('l10n_ru_doc.report_account_invoice_bill')
report_account_invoice_act = self.env.ref('l10n_ru_doc.report_account_invoice_act')
for print_submenu in res.get('toolbar', {}).get('print', []):
if print_submenu['id'] == report_account_invoice_bill.id:
res['toolbar']['print'].remove(print_submenu)
if print_submenu['id'] == report_account_invoice_act.id:
res['toolbar']['print'].remove(print_submenu)
return res
Thanks!
Ảnh đại diện
Huỷ bỏ
Tác giả

Solution:

Use two methods

@api.multi

def create_action(self):

""" Create a contextual action for each report. """

for report in self:

model = self.env['ir.model']._get(report.model)

report.write({'binding_model_id': model.id, 'binding_type': 'report'})

return True

@api.multi

def unlink_action(self):

""" Remove the contextual actions created for the reports. """

self.check_access_rights('write', raise_exception=True)

self.filtered('binding_model_id').write({'binding_model_id': False})

return True

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

add menu=False to report action

      id="account_invoices"

      model="account.invoice"

      string="Invoices"

      report_type="qweb-pdf"

      name="account.report_invoice_with_payments"

      file="account.report_invoice_with_payments"

      attachment="(object.state in ('open','in_payment','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"

      print_report_name="(object._get_report_base_filename())"

      groups="account.group_account_invoice"

    menu =False

  />

Video: https://www.youtube.com/watch?v=lVMDXpqasic&t=1s

Ảnh đại diện
Huỷ bỏ

It works perfectly, thank you!

Great Answer, thank you

just Add

menu="False"

how to set menu false based on state

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

If you want to hide the particulate report from the print menu then you can hide using the fields_view_get() function.I  added the below snippet code. This code may help you.

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
    ##Sample Code of Hide print ,action menu and particular report
    res = super().fields_view_get(view_id, view_type, toolbar, submenu)
    remove_report_id = self.env.ref('purchase.report_purchase_quotation').id
    if view_type == 'form' and remove_report_id and \
        toolbar and res['toolbar'] and res['toolbar'].get('print'):
        remove_report_record = [rec for rec in res['toolbar'].get('print') if rec.get('id')==                                 remove_report_id]
        if remove_report_record and remove_report_record[0]:
             res['toolbar'].get('print').remove(remove_report_record[0])
    return res
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello,
There is an inexpensive app which can allow you to do that:

\https://www.odoo.com/apps/modules/12.0/hide_any_report/​

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

Hi Gleb,

i think you need to first find the report external id defined in XML file and then inherit that XML code and add parameter invisible="1" to that code using xpath.

e.g. i have one report in account module and i want to hide then

<report

      id="account_invoices"

      model="account.invoice"

      string="Invoices"

      report_type="qweb-pdf"

      name="account.report_invoice_with_payments"

      file="account.report_invoice_with_payments"

      attachment="(object.state in ('open','in_payment','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"

      print_report_name="(object._get_report_base_filename())"

      groups="account.group_account_invoice"

  />


Then add invisible parameter like:


<report

      id="account.account_invoices"

      invisible="1"

      model="account.invoice"

      string="Invoices"

      report_type="qweb-pdf"

      name="account.report_invoice_with_payments"

      file="account.report_invoice_with_payments"

      attachment="(object.state in ('open','in_payment','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"

      print_report_name="(object._get_report_base_filename())"

      groups="account.group_account_invoice"

  />

There is one module available to hide print button: https://goo.gl/nuvnmw

Accept and upvote answer if helpful

Thanks and regards

Haresh Kansara

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 2 25
940
1
thg 8 25
515
0
thg 8 25
295
0
thg 7 25
1309
0
thg 7 25
3