Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
15819 Vizualizări

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')]}"

/>



 

Imagine profil
Abandonează
Cel mai bun răspuns

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.


Imagine profil
Abandonează

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

Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
feb. 21
3732
0
feb. 18
2890
3
iun. 17
5822
0
ian. 16
3777
2
aug. 19
4481