跳至內容
Odoo 選單
  • 登入
  • 免費試用
  • 應用程式
    財政
    • 會計
    • 發票
    • 開支報銷
    • 試算表 (BI)
    • 文件管理
    • 電子簽名
    銷售
    • 客戶關係
    • 銷售
    • POS 銷售點管理 - 零售
    • POS 銷售點管理 - 餐廳
    • 訂閱
    • 租賃
    網站
    • 網站製作
    • 電子商務
    • 網誌
    • 討論區
    • 線上客服
    • 網上學習
    供應鏈
    • 庫存
    • 製造管理
    • 產品生命周期
    • 採購
    • 保養維護
    • 品質管理
    人力資源
    • 員工管理
    • 招聘
    • 休假
    • 工作表現評核
    • 內部推薦
    • 車隊管理
    市場推廣
    • 社交媒體推廣
    • 電郵推廣
    • 短訊營銷
    • 活動
    • 自動化推廣
    • 網上調查
    服務
    • 專案管理
    • 工時管理
    • 外勤服務管理
    • 技術支援
    • 工作規劃
    • 預約管理
    生產力
    • 聊天
    • 批核
    • 物聯網
    • VoIP
    • 知識庫
    • WhatsApp
    第三方應用程式 Odoo Studio Odoo 雲端平台
  • 行業
    零售
    • 書店
    • 服裝店
    • 家具店
    • 食品雜貨店
    • 五金店
    • 玩具店
    餐飲及款待
    • 酒吧及酒館
    • 餐廳
    • 快餐
    • 賓館
    • 飲品分銷商
    • 酒店
    房地產
    • 地產代理公司
    • 建築師事務所
    • 建造業
    • 物業管理
    • 園藝
    • 業主聯會
    顧問服務
    • 會計公司
    • Odoo 合作夥伴
    • 市場推廣公司
    • 律師事務所
    • 人才招募
    • 審計及認證
    製造管理
    • 紡織
    • 金屬
    • 家具
    • 食品
    • 啤酒廠
    • 企業禮品
    保健與健身
    • 運動俱樂部
    • 眼鏡店
    • 健身中心
    • 健康從業人員
    • 藥房
    • 髮型屋
    技術行業
    • 雜工
    • IT 硬體與支援
    • 太陽能系統
    • 鞋匠
    • 清潔服務
    • 暖通空調服務
    其他
    • 非牟利組織
    • 環境保護機構
    • 廣告板租賃
    • 攝影服務
    • 自行車租賃
    • 軟體經銷商
    瀏覽所有行業
  • 社群
    學習
    • 教學影片
    • 使用說明
    • 認證
    • 培訓
    • 網誌
    • Podcast
    增強教學效能
    • 教育計劃
    • Scale Up! 商業遊戲
    • 到訪 Odoo
    取得軟件
    • 下載
    • 版本對照表
    • 版本說明
    合作
    • GitHub
    • 討論區
    • 活動
    • 翻譯
    • 成為合作夥伴
    • 合作夥伴服務
    • 登記你的會計服務公司
    獲取服務相關資料
    • 尋找合作夥伴
    • 尋找會計服務
    • 預約顧問諮詢
    • 安裝及推行服務
    • 客戶案例
    • 支援
    • 軟件升級
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    預約示範
  • 定價
  • 技術支援

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • 客戶關係
  • e-Commerce
  • 會計
  • 庫存
  • PoS
  • 專案管理
  • MRP
All apps
只限註冊用戶才可與社群互動。
所有帖文 人 獎章
標籤 (查看所有)
odoo accounting v14 pos v15
關於此討論區
只限註冊用戶才可與社群互動。
所有帖文 人 獎章
標籤 (查看所有)
odoo accounting v14 pos v15
關於此討論區
支援

How to display needaction count only in one menu ?

訂閱

此帖文有活動時,接收通知

此問題已被標幟
menuitemneedaction8.0
21 回覆
15570 瀏覽次數
頭像
Emanuel Cino

I have several menus pointing to a same object. I would like to display a needaction count in the menuitem, but so far I was only able to display the same count in all menuitems pointing to my object.

Is it possible to have a different counts for the same object but different menuitems ? Or at least, is it possible to show the count in only one menuitem and hide it in the others ?

1
頭像
捨棄
頭像
Axel Mendoza
最佳答案

Check how it is done in quotations/sale order as example

Edited

===========================================

When you put your model to inherit from the model ir.needaction_mixin, it's because you wanna indicate that there are some records that need an action and to indicate who are those records you need to override the method _needaction_domain_get to return a domain that will be used in combination with the menu action domain to filter the model records to display the count result. In the case of the sale.order it inherit from mail.thread that implements the _needaction_domain_get to display unread messages in the records.

For your case you just need to define a different domain for every menu action for the same object and of course the method _needaction_domain_get that build the domain for select the record count that need an action.

If your requirement it's not based on the domain of the menu action? that affects also your records universe in that menu, then you can go ok by specifying some different value in the context of the menus actions and use the value to build the domain in the method _needaction_domain_get based on the value of the context, something like this:

def _needaction_domain_get(self, cr, uid, context=None):
    if context.get('count_action') == 'menu1':
        return [('active_code','=','1')]
    elif context.get('count_action') == 'menu2':
        return [('active_code','=','2')]
    #else not need for menu3
    return [('active_code','=','3')]

then for the 3 menus you need to put the count_action key with the respective value.

================================================================

How to receive the action context in the _needaction_domain_get? You need to override the get_needaction_data of ir.ui.view to do that by simply copy the original code and changing the right lines, there is no other way. I highlights the changes:

class ir_ui_menu(osv.osv):
_inherit = 'ir.ui.menu'


def get_needaction_data(self, cr, uid, ids, context=None):
""" Return for each menu entry of ids :
- if it uses the needaction mechanism (needaction_enabled)
- the needaction counter of the related action, taking into account
the action domain
"""
if context is None:
context = {}
res = {}
menu_ids = set()
for menu in self.browse(cr, uid, ids, context=context):
menu_ids.add(menu.id)
ctx = None
if menu.action and menu.action.type in ('ir.actions.act_window', 'ir.actions.client') and menu.action.context:
try:
# use magical UnquoteEvalContext to ignore undefined client-side variables such as `active_id`
eval_ctx = tools.UnquoteEvalContext(**context)
ctx = eval(menu.action.context, locals_dict=eval_ctx, nocopy=True) or None
except Exception:
# if the eval still fails for some reason, we'll simply skip this menu
pass
menu_ref = ctx and ctx.get('needaction_menu_ref')
if menu_ref:
if not isinstance(menu_ref, list):
menu_ref = [menu_ref]
model_data_obj = self.pool.get('ir.model.data')
for menu_data in menu_ref:
try:
model, id = model_data_obj.get_object_reference(cr, uid, menu_data.split('.')[0], menu_data.split('.')[1])
if (model == 'ir.ui.menu'):
menu_ids.add(id)
except Exception:
pass

menu_ids = list(menu_ids)

for menu in self.browse(cr, uid, menu_ids, context=context):
res[menu.id] = {
'needaction_enabled': False,
'needaction_counter': False,
}
if menu.action and menu.action.type in ('ir.actions.act_window', 'ir.actions.client') and menu.action.res_model:
if menu.action.res_model in self.pool:
obj = self.pool[menu.action.res_model]
if obj._needaction:
if menu.action.type == 'ir.actions.act_window':
dom = menu.action.domain and eval(menu.action.domain, {'uid': uid}) or []
else:
dom = eval(menu.action.params_store or '{}', {'uid': uid}).get('domain')
res[menu.id]['needaction_enabled'] = obj._needaction
if menu.action.context:
act_ctx = dict(context, **menu.action.context)
else:
act_ctx = context

res[menu.id]['needaction_counter'] = obj._needaction_count(cr, uid, dom, context=act_ctx)
return res


 

4
頭像
捨棄
Emanuel Cino
作者

Thank you, can you at least point me where to look at ? The only thing I can see in sale module is that sale_order inherits from "ir.needaction_mixin"

Axel Mendoza

yes, let me explain a little more

Axel Mendoza

my answer is edited with the explanation

Emanuel Cino
作者

I tried with the context, but the context defined in the action is not passed to _needaction_domain_get method. I am using version 8 just in case.

Axel Mendoza

Sorry for the delay to respond, you are right, let me complete the answer one more time to allow you to receive the action context.

Axel Mendoza

My first answer was updated to add the needed extension. Odoo forum have the behavior of not notify me about some comments or updates

Emanuel Cino
作者

Thanks to your answer I was able to make it !! However I didn't have to copy paste the whole method. In version, all I needed to do was this : ``` @api.multi def get_needaction_data(self): res = dict() for menu in self: if menu.action and menu.action.context: new_context = dict() try: new_context = ast.literal_eval(menu.action.context) new_context.update(self.env.context) except: new_context = self.env.context res.update( super(IrUiMenu, menu.with_context(new_context)).get_needaction_data()) return res ```

Emanuel Cino
作者

Oh this doesn't format well the code in the comments... I will just post it underneath but I accepted your answer. Thanks again !

頭像
Pawan
最佳答案

Emanuel, in order to show counts in each menu of same object, you can proceed in th eorder below.

'needaction_menu_ref': ['list_of_other_menu_ids_of_same_object']

to your respective Menu's action's context in xml file....

suppose on menu with id 'a' you will have :

'needaction_menu_ref': ['b', 'c']

suppose on menu with id 'b' you will have :

'needaction_menu_ref': ['a', 'c']

and so on...... then add this function to your object inheriting"ir.needaction_mixin":

@api.model

def _needaction_domain_get(self):

    return[('active', '=', True)] # you can modify as per your requirement.....

and you can also refer to similar post: https://www.odoo.com/forum/help-1/question/how-can-i-count-records-in-domain-and-display-it-in-line-with-menu-89943#answer-89945

Hope this helps you.......

2
頭像
捨棄
Emanuel Cino
作者

Hey, this is exactly what I don't want to do. I want count in only one menu, or different counts for different menus (but all for same object). I hope it's clearer

Pawan

hi,
your statement:different counts for different menus (but all for same object)
My statement:in order to show counts in each menu of same object i can't get where i misunderstood you...., i gave you the solution to get the [different]counts on different(each n every) menus of same object(but all for same object). Please clear me if i am wrong...
thanks

Pawan

however, apart from all these, you need to provide domain(like for states, [('state', '=', 'draft)] in one menu and so on....) in every actions for the data you want to see in each menu...

Emanuel Cino
作者

Ok, I thought when reading your answer your solution was to display count on all menus (same count). I will try

Emanuel Cino
作者

Hi again, I tried but it doesn't work. In fact I have the same domain for different menus (I display the same items but with different views) and I would like to be able to specify different needactions for these menus. There should be a way of returning a different domain in method _needaction_domain_get depending on which action called it. In that sense, Axel Mendoza's answer was close to what I need, unfortunately the context is not passed in _needaction_domain_get method. Do you have any other idea how to achieve this ?

Pawan

the domain which you will pass in the "domain" property of your action, you can get it in your _needaction_domain_get by calling its SUPER function, then you can use it as either to return same value or manipluate it(applying your "If's") as per your wish..... or next thing if you are on odoo 8 , you can browse context using "self.context", for Axel's method.....

Emanuel Cino
作者

I tried again but calling SUPER inside _needaction returns always [('message_unread', '=', True)] no matter in which action I am. And again, the context inside the method (using self.env.context) does not contain the values I add in the xml action context field. It only contains basic values (language, user, timezone).

Pawan

OK, so for your requirement you can override "_needaction_count()" method, and there you will get the domain passed in your action, which you can use as u want....
def _needaction_count(self, cr, uid, domain=None, context=None):
""" Get the number of actions uid has to perform. """
print domain, res, 'YOUR DOMAIN and TOTAL ROCORD ITEMS (for your manipulations) '
res = super(crm_lead, self)._needaction_count(cr, uid, domain, context)
return res

Emanuel Cino
作者

_needaction_count gets neither the context... however Axel Mendoza solved the issue.

頭像
Emanuel Cino
作者 最佳答案

My final code in model ir_ui_menu (inherited) :

@api.multi

def get_needaction_data(self):
res = dict()
for menu in self:
if menu.action and menu.action.context:
new_context = dict()
try:
new_context = ast.literal_eval(menu.action.context)
new_context.update(self.env.context)
except:
new_context = self.env.context
res.update(
super(IrUiMenu,
menu.with_context(new_context)).get_needaction_data())
return res


In my view's action:

<record model="ir.actions.act_window" id="action_follow_sds">

     <field name="context">{'count_menu': 'menu_follow_sds'}</field>
</record>

In my model :

@api.model

def _needaction_domain_get(self):
if self.env.context.get('count_menu') == 'menu_follow_sds':
return [('sds_state', '=', 'sub_waiting')]
return False
1
頭像
捨棄
頭像
Marco Costella
最佳答案

Hello,

I had the same problem (openerp v7) and i found this post. I like no one of the proposed solution so i read the code and i found this:

res[menu.id]['needaction_enabled'] = obj._needaction_needaction
res[menu.id]['needaction_counter'] = obj._needaction_count(cr, uid, dom, context=context)

You can inherit the function _needaction_count in your object and set the results has you prefer:

def _needaction_count(self, cr, uid, dom, context=None):
context = context or {}
if (dom):
res = len(self.search(cr, uid, dom, context=context))
else:
res = super(todo_todo, self)._needaction_count(cr, uid, dom, context=context)
return res

The dom parameter of the function is the domain of the menu action:

<field name="domain">[('state', '=', 'created')]</field>

If the result of the function is 0 the counter is not show.


I hope this will help!

Ciao

0
頭像
捨棄
喜歡這則討論?不要只閱讀,加入發表意見吧!

今天就建立帳戶,享受獨家功能,與我們精彩的社群互動!

註冊
相關帖文 回覆 瀏覽次數 活動
Get menuitem list 已解決
menuitem
頭像
頭像
頭像
3
12月 21
8224
Clients queue system
8.0
頭像
頭像
7
9月 20
8371
Disabled Menu Items Without using groups
menuitem
頭像
0
12月 18
3276
How to delete menuitem? 已解決
menuitem
頭像
頭像
頭像
頭像
頭像
7
10月 18
23443
odoo 8.0 crash after update crm module
8.0
頭像
頭像
1
11月 17
4944
社群
  • 教學影片
  • 使用說明
  • 討論區
開源
  • 下載
  • GitHub
  • Runbot 測試環境
  • 翻譯
服務
  • odoo.sh 網頁寄存
  • 支援
  • 升級
  • 自訂功能開發
  • 教育及培訓
  • 尋找會計服務
  • 尋找合作夥伴
  • 成為合作夥伴
關於我們
  • 關於 Odoo 公司
  • 品牌資產
  • 聯絡我們
  • 招聘
  • 活動
  • Podcast
  • 網誌
  • 客戶
  • 法律 • 私隱政策
  • 安全性
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo 是一套開放源碼的商業管理系統,涵蓋你公司全部的營運需要,包括客戶關係管理(CRM)、電子商務、會計、庫存管理、POS(銷售點管理)、專案管理等應用程式。

Odoo 的獨特價值是非常簡單易用,同時將不同應用程式完美整合。

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now