Ansu Mary Jacob
Ansu Mary Jacob

Reputation: 1

how to restrict seeing vendor bill report in accounting invoice in odoo16 ? (move_type)

@api.model
    def _get_view(self, view_id=None, view_type='form',toolbar=False, submenu=False, **options):
        
res = super()._get_view(view_id, view_type, **options)

        field_info =self.env['account.move'].fields_get(['move_type'])
        move_type_options = field_info['move_type']['selection']
        in_invoice_options = [option for option in move_type_options if option[0] == 'in_invoice']
        if view_type == 'form' and self._name == 'account.move' and in_invoice_options and in_invoice_options[0][0] == 'in_invoice':
            if 'invoice' in res and 'report_customer_invoice' in res['invoice']:
                del res['invoice']['report_customer_invoice']
        return res

it is not working .. please help to correct the code . thank you

Upvotes: 0

Views: 126

Answers (1)

Ansu Mary Jacob
Ansu Mary Jacob

Reputation: 1

class AccountMove(models.Model):
    _inherit = "account.move"
    

    @api.model
    def get_views(self, views, options=None):
        res = super().get_views(views, options)
        default_type = self._context.get('default_move_type', False)
        
        if default_type and default_type in ['in_invoice','out_refund','out_receipt','in_receipt']:
            remove_report_id = self.env.ref(
                "zb_account_reports.report_customer_invoice").id
            toolbar = res["views"]["form"]["toolbar"]
            if res["views"].get("form", {}) and remove_report_id and \
                    toolbar and toolbar and toolbar.get('print'):
                remove_report_record = [rec for rec in toolbar.get(
                    'print') if rec.get("id") == remove_report_id]
                if remove_report_record and remove_report_record[0]:
                    toolbar.get('print').remove(remove_report_record[0])
        return res

Upvotes: 0

Related Questions