Skip to Content
Menu
This question has been flagged

I've made a report for account.move model and when I open any invoice you can find it at top, in that print button dropdown. It works however I would like to hide it based on the state of variable that the current account.move record has. My current code is to try something like this:


def fields_view_get(self, view_id=None, view_type='tree', toolbar=False, submenu=False):
res = super().fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)

# TODO I found out that instance variables are not available after I finished the below code :/
if not self.some_variable:
return res

if self._context.get("validate") or not res.get("toolbar") or not res["toolbar"].get("print"):
return res

report = self.env.ref("my_report")
if not report:
return res

report_id = report.id
base: List[dict] = res["toolbar"]["print"]

to_remove: Optional[dict] = None
for sub_dict in base:
if sub_dict.get("id") == report_id:
to_remove = sub_dict
break

if to_remove:
base.remove(to_remove)

return res
This is in my model that inherited account.move which is basically:

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

 some_variable = fields.Boolean(default=False)

I would like to hide that certain my_report from showing up in the print dropdown if some_variable is set to True.


I'd like a way without having a separate button (so it remains in print dropdown)-


Avatar
Discard
Related Posts Replies Views Activity
3
May 23
2626
0
Jul 22
40
1
Mar 21
8422
2
Jan 23
5799
1
Dec 22
2519