This question has been flagged
4 Replies
22823 Views
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!
Avatar
Discard
Author

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

Best Answer

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

Avatar
Discard

It works perfectly, thank you!

Great Answer, thank you

just Add

menu="False"

how to set menu false based on state

Best Answer

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
Avatar
Discard
Best Answer

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

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

Avatar
Discard
Best Answer

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

Avatar
Discard