Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
15810 Widoki

I am new in odoo. I am using Odoo 8. It is under stock/stock_report.xml. I inherit one menu option (top dropdown menu) report in my new module. Now I want to show it based on some condition. More clearly, menu="False" if ('state', '==', 'assigned') otherwise, menu="True".

How can I write this in menu. I have tried like following way. But it does not work. Or, if there any other way to do. I must have to do it by inheriting.

<report

string="Picking test"

id="stock.action_report_picking"

model="stock.picking"

report_type="qweb-pdf"

name="stock.report_picking"

file="stock.report_picking"

menu="{'False':['|',('state', '==', 'assigned')]}"

/>



 

Awatar
Odrzuć
Najlepsza odpowiedź

Hello,

you can achieve this thing via fields_view_get method inherit in your .py file.

so try below code and some as per you need do some changes according to your requirement.

@api.model

def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):

res = super(stock_picking, self).fields_view_get(

view_id=view_id,

view_type=view_type,

toolbar=toolbar,

submenu=submenu)

if res.get('fields').get('state')['selection'][0][1] == 'assigned':

if res.get('toolbar', False) and res.get('toolbar').get('print', False):

reports = res.get('toolbar').get('print')

for report in reports:

if report.get('report_file', False) and report.get('report_file') == 'stock.report_picking':

res['toolbar']['print'].remove(report)

return res



I Hope it will help you.

Thanks.


Awatar
Odrzuć

Thanks for the help! It works but, in my case, not in all account.invoice views, only just in one. In the other ones, the option appears in the Print menu, but in the fields_view_get() method that report menu option seems not exists in this loop:

def fields_view_get():

reports = res['toolbar']['print']

for report in reports:

# Here, the logger doesn't show the report option we want to remove

logger.error('## REPORT ## %r', report)

It works me.....! Thank you.
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
context = self._context
res = super(AccountMoveLineInherit, self).fields_view_get(view_id=view_id,view_type=view_type,toolbar=toolbar,submenu=submenu)
if res.get('toolbar', False) and res.get('toolbar').get('print', False):
reports = res.get('toolbar').get('print')
for report in reports:
if context.get('journal_type') and context.get('journal_type') == 'sales':
if report.get('report_file', False) and report.get('report_file') == 'report_account_moves_line_pur_xlsx':
res['toolbar']['print'].remove(report)
if context.get('journal_type') and context.get('journal_type') == 'purchase':
if report.get('report_file', False) and report.get('report_file') == 'report_account_moves_line_sale_xlsx':
res['toolbar']['print'].remove(report)
return res

Thanks all. This is the one more example:

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

if res.get('toolbar', False) and res.get('toolbar').get('print', False):
reports = res.get('toolbar').get('print')

for report in reports:
if report.get('report_name', False) == 'account.report_invoice_with_payments' or report.get('report_name', False) == 'account.report_invoice':
res['toolbar']['print'] = []

return res

Najlepsza odpowiedź

Its again a doubt .

fields_view_get method doesnt work first
it works when a reload occurs
how to solve the problem,i am removing one report from the menu depending on company id
it only works on refreshing of form

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
lut 21
3731
0
lut 18
2889
3
cze 17
5822
0
sty 16
3777
2
sie 19
4481