Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
15825 Lượt xem

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

/>



 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.


Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 2 21
3738
0
thg 2 18
2892
3
thg 6 17
5823
0
thg 1 16
3779
2
thg 8 19
4483