콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2891 화면

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)-


아바타
취소
관련 게시물 답글 화면 활동
3
5월 23
3972
0
7월 22
40
1
3월 21
10703
2
1월 23
7407
1
12월 22
3613