[MERGE] Merged with main server, holding the need_action mechanism
bzr revid: tde@openerp.com-20120403171512-pb7l4g6pnqryxudm
This commit is contained in:
commit
6fdeb5ec98
|
@ -1,19 +1,19 @@
|
|||
Need action mechanism
|
||||
=====================
|
||||
|
||||
base.needaction mixin class
|
||||
+++++++++++++++++++++++++++
|
||||
ir.needaction mixin class
|
||||
++++++++++++++++++++++++++
|
||||
|
||||
This revision adds a mixin class for objects using the need action feature.
|
||||
|
||||
Need action feature can be used by objects willing to be able to signal that an action is required on a particular record. If in the business logic an action must be performed by somebody, for instance validation by a manager, this mechanism allows to set a list of users asked to perform an action.
|
||||
|
||||
This class wraps a table (base.needaction_users_rel) that behaves like a many2many field. However, no field is added to the model inheriting from base.needaction. The mixin class manages the low-level considerations of updating relationships. Every change made on the record calls a method that updates the relationships.
|
||||
This class wraps a class (ir.needaction_users) that behaves like a many2many field. However, no field is added to the model inheriting from base.needaction. The mixin class manages the low-level considerations of updating relationships. Every change made on the record calls a method that updates the relationships.
|
||||
|
||||
Objects using the need_action feature should override the ``get_needaction_user_ids`` method. This methods returns a dictionary whose keys are record ids, and values a list of user ids, like in a many2many relationship. Therefore by defining only one method, you can specify if an action is required by defining the users that have to do it, in every possible situation.
|
||||
|
||||
This class also offers several global services,:
|
||||
- ``needaction_get_record_ids``: for a given model_name and uid, get all record ids that ask this user to perform an action. This mechanism is used for instance to display the number of pending actions in menus, such as Leads (12)
|
||||
- ``needaction_get_record_ids``: for the current model and uid, get all record ids that ask this user to perform an action. This mechanism is used for instance to display the number of pending actions in menus, such as Leads (12)
|
||||
- ``needaction_get_action_count``: as ``needaction_get_record_ids`` but returns only the number of action, not the ids (performs a search with count=True)
|
||||
- ``needaction_get_user_record_references``: for a given uid, get all the records that ask this user to perform an action. Records are given as references, a list of tuples (model_name, record_id)
|
||||
|
||||
|
@ -25,7 +25,7 @@ This revision adds three functional fields to ``ir.ui.menu`` model :
|
|||
- ``needaction_uid_ctr``: integer field. If the target model uses the need action mechanism, this field gives the number of actions the current user has to perform.
|
||||
- ``needaction_record_ids``: many2many field. If the target model uses the need action mechanism, this field holds the ids of the record requesting the user to perform an action.
|
||||
|
||||
Those fields are functional, because they must be recalculated for each user, and each time menus are displayed. ``needaction_uid_ctr`` takes into account the domain of the action, in order to display accurate numbers.
|
||||
Those fields are functional, because they depend on the user and must therefore be computed at every refresh, each time menus are displayed. The use of the need action mechanism is done by taking into account the action domain in order to display accurate results. When computing the value of the functional fields, the ids of records asking the user to perform an action is concatenated to the action domain. A counting search is then performed on the model, giving back the number of action the users has to perform, limited to the domain of the action.
|
||||
|
||||
Addon implementation example
|
||||
++++++++++++++++++++++++++++
|
||||
|
|
|
@ -8,14 +8,14 @@ msgstr ""
|
|||
"Project-Id-Version: openobject-server\n"
|
||||
"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"POT-Creation-Date: 2012-02-08 00:44+0000\n"
|
||||
"PO-Revision-Date: 2012-03-31 07:17+0000\n"
|
||||
"PO-Revision-Date: 2012-04-02 21:12+0000\n"
|
||||
"Last-Translator: Akira Hiyama <Unknown>\n"
|
||||
"Language-Team: Japanese <ja@li.org>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Launchpad-Export-Date: 2012-04-01 04:38+0000\n"
|
||||
"X-Generator: Launchpad (build 15032)\n"
|
||||
"X-Launchpad-Export-Date: 2012-04-03 04:53+0000\n"
|
||||
"X-Generator: Launchpad (build 15052)\n"
|
||||
|
||||
#. module: base
|
||||
#: model:res.country,name:base.sh
|
||||
|
@ -13889,7 +13889,7 @@ msgstr "ハード島とマクドナルド諸島"
|
|||
msgid ""
|
||||
"External Key/Identifier that can be used for data integration with third-"
|
||||
"party systems"
|
||||
msgstr ""
|
||||
msgstr "サードパーティのシステムとのデータ統合のために利用する外部キー / 識別子"
|
||||
|
||||
#. module: base
|
||||
#: model:ir.module.module,description:base.module_mrp_operations
|
||||
|
@ -13924,6 +13924,31 @@ msgid ""
|
|||
"\n"
|
||||
" "
|
||||
msgstr ""
|
||||
"\n"
|
||||
"このモジュールは製造オーダー行(\"ワークセンタ\"のタブ内)の中に状態、開始日付、中止日付を追加します。\n"
|
||||
"============================================================================="
|
||||
"================================\n"
|
||||
"\n"
|
||||
"状態:ドラフト、確認、完了、キャンセル\n"
|
||||
"終了する、確認する、キャンセルする時に、製造オーダーは全ての状態行を状態に応じて設定する。\n"
|
||||
"\n"
|
||||
"メニューの作成:\n"
|
||||
" 製造 > 製造 > ワークオーダー\n"
|
||||
"\n"
|
||||
"これは、製造オーダーのワークセンタ行のビューです。\n"
|
||||
"\n"
|
||||
"ワークセンタタブの下に製造オーダーのフォームビューにボタンを追加して下さい:\n"
|
||||
" ・ 開始(確認状態に設定)、開始日付の設定\n"
|
||||
" ・ 完了(完了状態に設定)、中止日付の設定\n"
|
||||
" ・ ドラフトに設定(ドラフト状態に設定)\n"
|
||||
" ・ キャンセル(キャンセル状態に設定)\n"
|
||||
"\n"
|
||||
"製造オーダーが\"製造可能\"になった時、操作は確認済になります。製造オーダーが終了した時、操作は完了になります。\n"
|
||||
"\n"
|
||||
"項目の遅れは遅れ(中止日付 - 開始日付)です。\n"
|
||||
"それで、理論的な遅れと実際の遅れを比較できます。\n"
|
||||
"\n"
|
||||
" "
|
||||
|
||||
#. module: base
|
||||
#: model:ir.module.module,description:base.module_auction
|
||||
|
@ -13947,6 +13972,21 @@ msgid ""
|
|||
" * Objects By Day (graph)\n"
|
||||
" "
|
||||
msgstr ""
|
||||
"\n"
|
||||
"このモジュールはオークションの品物、売り手と買い手の記録を管理します。\n"
|
||||
"============================================================================="
|
||||
"====\n"
|
||||
"\n"
|
||||
"入札の管理、支払いや売れた品物の追跡、品物の配達を含む未払いなどのオークションを完全に管理します。\n"
|
||||
"\n"
|
||||
"オークションのためのダッシュボードは以下を含みます:\n"
|
||||
" ・ 最新のオブジェクト(リスト)\n"
|
||||
" ・ 最新の預り金(リスト)\n"
|
||||
" ・ オブジェクトの統計(リスト)\n"
|
||||
" ・ 合計落札(グラフ)\n"
|
||||
" ・ 最小 / 平均 / 最大(グラフ)\n"
|
||||
" ・ 日別のオブジェクト(グラフ)\n"
|
||||
" "
|
||||
|
||||
#. module: base
|
||||
#: model:ir.module.module,description:base.module_base_crypt
|
||||
|
@ -13983,6 +14023,33 @@ msgid ""
|
|||
"\n"
|
||||
" "
|
||||
msgstr ""
|
||||
"\n"
|
||||
"データベースの中のクリアテキストパスワードを安全なハッシュにより置き換えます。\n"
|
||||
"===============================================================\n"
|
||||
"\n"
|
||||
"存在するユーザベースのために、base_cryptをインストールした場合、即座にクリアテキストパスワードの除去を行います。\n"
|
||||
"\n"
|
||||
"全てのパスワードは誰かがデータベースの中のオリジナルのパスワードを読むことを防止\n"
|
||||
"するために、安全、ハッシュ暗号化で処理され置き換えられます。\n"
|
||||
"\n"
|
||||
"このモジュールをインストール後は、ユーザがパスワードを忘れた場合はそれを取り戻すことは\n"
|
||||
"できません。その場合はアドミンによって新しいパスワードをセットするのが唯一の方法です。\n"
|
||||
"\n"
|
||||
"セキュリティの警告\n"
|
||||
"++++++++++++++++\n"
|
||||
"このモジュールをインストールしても、XML -RPCS、あるいはHTTPのような安全なプロトコル\n"
|
||||
"を使っていないなら、パスワードはネットワーク上を暗号化されないで転送されますので、\n"
|
||||
"他のセキュリティ対策を無視して良いということではありません。\n"
|
||||
"また、データベースに格納された他を保護しません。それは重要なデータを含むかもしれません。\n"
|
||||
"全てのエリアに対して、システム管理者によって以下のような適切なセキュリティ対策の実装が要求されます。\n"
|
||||
"データベースバックアップ、システムファイル、リモートシェルアクセス、物理サーバアクセスなどに対する保護\n"
|
||||
"\n"
|
||||
"LDAP認証との統合\n"
|
||||
"+++++++++++++++++++++++++++++++++++\n"
|
||||
"このモジュールは現在、user_ldapモジュールと互換性はありません。同時にインストールをした場合、\n"
|
||||
"完全にLDAP認証を無効にするでしょう。\n"
|
||||
"\n"
|
||||
" "
|
||||
|
||||
#. module: base
|
||||
#: field:ir.actions.act_window,view_id:0
|
||||
|
@ -13992,22 +14059,22 @@ msgstr "ビューの参照"
|
|||
#. module: base
|
||||
#: model:ir.module.category,description:base.module_category_sales_management
|
||||
msgid "Helps you handle your quotations, sale orders and invoicing."
|
||||
msgstr ""
|
||||
msgstr "見積書、販売注文書、請求書の処理に役立ちます。"
|
||||
|
||||
#. module: base
|
||||
#: field:res.groups,implied_ids:0
|
||||
msgid "Inherits"
|
||||
msgstr ""
|
||||
msgstr "継承"
|
||||
|
||||
#. module: base
|
||||
#: selection:ir.translation,type:0
|
||||
msgid "Selection"
|
||||
msgstr ""
|
||||
msgstr "選択"
|
||||
|
||||
#. module: base
|
||||
#: field:ir.module.module,icon:0
|
||||
msgid "Icon URL"
|
||||
msgstr ""
|
||||
msgstr "アイコンのURL"
|
||||
|
||||
#. module: base
|
||||
#: field:ir.actions.act_window,type:0
|
||||
|
@ -14021,12 +14088,12 @@ msgstr ""
|
|||
#: field:ir.actions.url,type:0
|
||||
#: field:ir.actions.wizard,type:0
|
||||
msgid "Action Type"
|
||||
msgstr ""
|
||||
msgstr "アクションタイプ"
|
||||
|
||||
#. module: base
|
||||
#: model:res.country,name:base.vn
|
||||
msgid "Vietnam"
|
||||
msgstr ""
|
||||
msgstr "ベトナム"
|
||||
|
||||
#. module: base
|
||||
#: model:ir.module.module,description:base.module_l10n_syscohada
|
||||
|
@ -14042,32 +14109,37 @@ msgid ""
|
|||
"Chad, Togo.\n"
|
||||
" "
|
||||
msgstr ""
|
||||
"このモジュールはOHADA領域の会計表を実装しています。\n"
|
||||
" 任意の会社や団体が財務会計の管理ができます。OHADAを使用する国は次のとおりです:\n"
|
||||
" ベナン、ブルキナファソ、カメルーン、中央アフリカ共和国、コモロ、コンゴ、コートジボワール、\n"
|
||||
" ガボン、ギニア、ギニアビサウ、赤道ギニア、マリ、ニジェール、コンゴ民主共和国、チャド、トーゴ\n"
|
||||
" "
|
||||
|
||||
#. module: base
|
||||
#: view:base.language.import:0
|
||||
#: model:ir.actions.act_window,name:base.action_view_base_import_language
|
||||
#: model:ir.ui.menu,name:base.menu_view_base_import_language
|
||||
msgid "Import Translation"
|
||||
msgstr ""
|
||||
msgstr "翻訳のインポート"
|
||||
|
||||
#. module: base
|
||||
#: field:res.partner.bank.type,field_ids:0
|
||||
msgid "Type fields"
|
||||
msgstr ""
|
||||
msgstr "項目のタイプ"
|
||||
|
||||
#. module: base
|
||||
#: view:ir.actions.todo:0
|
||||
#: field:ir.actions.todo,category_id:0
|
||||
#: field:ir.module.module,category_id:0
|
||||
msgid "Category"
|
||||
msgstr ""
|
||||
msgstr "分類"
|
||||
|
||||
#. module: base
|
||||
#: view:ir.attachment:0
|
||||
#: selection:ir.attachment,type:0
|
||||
#: selection:ir.property,type:0
|
||||
msgid "Binary"
|
||||
msgstr ""
|
||||
msgstr "二進数"
|
||||
|
||||
#. module: base
|
||||
#: field:ir.actions.server,sms:0
|
||||
|
@ -14078,12 +14150,12 @@ msgstr ""
|
|||
#. module: base
|
||||
#: model:res.country,name:base.cr
|
||||
msgid "Costa Rica"
|
||||
msgstr ""
|
||||
msgstr "コスタリカ"
|
||||
|
||||
#. module: base
|
||||
#: model:ir.module.module,shortdesc:base.module_base_module_doc_rst
|
||||
msgid "Generate Docs of Modules"
|
||||
msgstr ""
|
||||
msgstr "モジュールのドキュメントの生成"
|
||||
|
||||
#. module: base
|
||||
#: model:res.company,overdue_msg:base.main_company
|
||||
|
@ -14095,6 +14167,10 @@ msgid ""
|
|||
"queries regarding your account, please contact us.\n"
|
||||
"Thank you in advance.\n"
|
||||
msgstr ""
|
||||
"われわれの記録によれば、次の支払がまだ行われておりません。既に金額が支払われている\n"
|
||||
"場合には、どうぞ、この通知を無視して下さい。\n"
|
||||
"アカウントに関して何かご質問がありましたら、どうぞ、お問い合わせ下さい。\n"
|
||||
"よろしくお願いいたします。\n"
|
||||
|
||||
#. module: base
|
||||
#: model:ir.module.module,shortdesc:base.module_users_ldap
|
||||
|
|
|
@ -662,9 +662,9 @@
|
|||
<menuitem action="ir_action_wizard" id="menu_ir_action_wizard" parent="base.next_id_6"/>
|
||||
|
||||
<!-- Needaction mechanism -->
|
||||
<record model="ir.ui.view" id="view_notification_tree">
|
||||
<field name="name">ir.needaction_users_rel.tree</field>
|
||||
<field name="model">ir.needaction_users_rel</field>
|
||||
<record model="ir.ui.view" id="view_ir_needaction_users_tree">
|
||||
<field name="name">ir.needaction_users.tree</field>
|
||||
<field name="model">ir.needaction_users</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="sequence">10</field>
|
||||
<field name="arch" type="xml">
|
||||
|
@ -676,14 +676,14 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_view_needaction_users_rel" model="ir.actions.act_window">
|
||||
<record id="action_view_needaction_users" model="ir.actions.act_window">
|
||||
<field name="name">Need action relationships</field>
|
||||
<field name="res_model">ir.needaction_users_rel</field>
|
||||
<field name="res_model">ir.needaction_users</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_needaction_users_rel" name="Need actions" parent="base.menu_users" sequence="20" action="action_view_needaction_users_rel" groups="base.group_extended"/>
|
||||
<menuitem id="menu_needaction_users" name="Need actions" parent="base.menu_users" sequence="20" action="action_view_needaction_users" groups="base.group_extended"/>
|
||||
|
||||
<!-- Companies -->
|
||||
<menuitem id="menu_res_company_global"
|
||||
|
|
|
@ -24,9 +24,9 @@ from operator import itemgetter
|
|||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
class ir_needaction_users_rel(osv.osv):
|
||||
class ir_needaction_users(osv.osv):
|
||||
'''
|
||||
ir_needaction_users_rel holds data related to the needaction
|
||||
ir_needaction_users holds data related to the needaction
|
||||
mechanism inside OpenERP. A needaction is characterized by:
|
||||
- res_model: model of the record requiring an action
|
||||
- res_id: ID of the record requiring an action
|
||||
|
@ -34,7 +34,7 @@ class ir_needaction_users_rel(osv.osv):
|
|||
has to perform the action
|
||||
'''
|
||||
|
||||
_name = 'ir.needaction_users_rel'
|
||||
_name = 'ir.needaction_users'
|
||||
_description = 'Needaction relationship table'
|
||||
_rec_name = 'id'
|
||||
_order = 'id desc'
|
||||
|
@ -47,8 +47,43 @@ class ir_needaction_users_rel(osv.osv):
|
|||
ondelete='cascade', select=1, required=True),
|
||||
}
|
||||
|
||||
def _get_users(self, cr, uid, res_ids, res_model, context=None):
|
||||
"""Given res_ids of res_model, get user_ids present in table"""
|
||||
if context is None:
|
||||
context = {}
|
||||
needact_ids = self.search(cr, uid, [('res_model', '=', res_model), ('res_id', 'in', res_ids)], context=context)
|
||||
return map(itemgetter('res_id'), self.read(cr, uid, needact_ids, context=context))
|
||||
|
||||
class ir_needaction(osv.osv):
|
||||
def create_users(self, cr, uid, res_ids, res_model, user_ids, context=None):
|
||||
"""Given res_ids of res_model, add user_ids to the relationship table"""
|
||||
if context is None:
|
||||
context = {}
|
||||
for res_id in res_ids:
|
||||
for user_id in user_ids:
|
||||
self.create(cr, uid, {'res_model': res_model, 'res_id': res_id, 'user_id': user_id}, context=context)
|
||||
return True
|
||||
|
||||
def unlink_users(self, cr, uid, res_ids, res_model, context=None):
|
||||
"""Given res_ids of res_model, delete all entries in the relationship table"""
|
||||
if context is None:
|
||||
context = {}
|
||||
to_del_ids = self.search(cr, uid, [('res_model', '=', res_model), ('res_id', 'in', res_ids)], context=context)
|
||||
return self.unlink(cr, uid, to_del_ids, context=context)
|
||||
|
||||
def update_users(self, cr, uid, res_ids, res_model, user_ids, context=None):
|
||||
"""Given res_ids of res_model, update their entries in the relationship table to user_ids"""
|
||||
# read current records
|
||||
cur_users = self._get_users(cr, uid, res_ids, res_model, context=context)
|
||||
if len(cur_users) == len(user_ids) and all([cur_user in user_ids for cur_user in cur_users]):
|
||||
return True
|
||||
# unlink old records
|
||||
self.unlink_users(cr, uid, res_ids, res_model, context=context)
|
||||
# link new records
|
||||
self.create_users(cr, uid, res_ids, res_model, user_ids, context=context)
|
||||
return True
|
||||
|
||||
|
||||
class ir_needaction_mixin(osv.osv):
|
||||
'''Mixin class for objects using the need action feature.
|
||||
|
||||
Need action feature can be used by objects willing to be able to
|
||||
|
@ -57,7 +92,7 @@ class ir_needaction(osv.osv):
|
|||
validation by a manager, this mechanism allows to set a list of
|
||||
users asked to perform an action.
|
||||
|
||||
This class wraps a table (base.needaction_users_rel) that behaves
|
||||
This class wraps a class (ir.needaction_users) that behaves
|
||||
like a many2many field. However, no field is added to the model
|
||||
inheriting from base.needaction. The mixin class manages the low-level
|
||||
considerations of updating relationships. Every change made on the
|
||||
|
@ -71,7 +106,7 @@ class ir_needaction(osv.osv):
|
|||
that have to do it, in every possible situation.
|
||||
|
||||
This class also offers several global services,:
|
||||
- ``needaction_get_record_ids``: for a given model_name and uid, get
|
||||
- ``needaction_get_record_ids``: for the current model and uid, get
|
||||
all record ids that ask this user to perform an action. This
|
||||
mechanism is used for instance to display the number of pending
|
||||
actions in menus, such as Leads (12)
|
||||
|
@ -82,123 +117,82 @@ class ir_needaction(osv.osv):
|
|||
the records that ask this user to perform an action. Records
|
||||
are given as references, a list of tuples (model_name, record_id)
|
||||
'''
|
||||
_name = 'ir.needaction'
|
||||
_name = 'ir.needaction_mixin'
|
||||
_description = 'Need action of users on records API'
|
||||
|
||||
_columns = {
|
||||
}
|
||||
|
||||
#------------------------------------------------------
|
||||
# need action relationship management
|
||||
#------------------------------------------------------
|
||||
|
||||
def _get_users(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
needact_obj = self.pool.get('ir.needaction_users_rel')
|
||||
needact_ids = needact_obj.search(cr, uid, [('res_model', '=', self._name), ('res_id', 'in', ids)], context=context)
|
||||
return needact_obj.read(cr, uid, needact_ids, context=context)
|
||||
|
||||
def _link_users(self, cr, uid, ids, user_ids, context=None):
|
||||
"""Given ids of model self._name, add user_ids to the relationship table"""
|
||||
if context is None:
|
||||
context = {}
|
||||
needact_obj = self.pool.get('ir.needaction_users_rel')
|
||||
for id in ids:
|
||||
for user_id in user_ids:
|
||||
needact_obj.create(cr, uid, {'res_model': self._name, 'res_id': id, 'user_id': user_id}, context=context)
|
||||
return True
|
||||
|
||||
def _unlink_users(self, cr, uid, ids, context=None):
|
||||
"""Given ids of model self._name, delete all entries in the relationship table"""
|
||||
if context is None:
|
||||
context = {}
|
||||
needact_obj = self.pool.get('ir.needaction_users_rel')
|
||||
to_del_ids = needact_obj.search(cr, uid, [('res_model', '=', self._name), ('res_id', 'in', ids)], context=context)
|
||||
return needact_obj.unlink(cr, uid, to_del_ids, context=context)
|
||||
|
||||
def _update_users(self, cr, uid, ids, user_ids, context=None):
|
||||
"""Given ids of model self._name, update their entries in the relationship table to user_ids"""
|
||||
# read current records
|
||||
cur_needact_objs = self._get_users(cr, uid, ids, context=None)
|
||||
if len(cur_needact_objs) == len(user_ids) and all([cur_needact_obj['user_id'] in user_ids for cur_needact_obj in cur_needact_objs]):
|
||||
return True
|
||||
# unlink old records
|
||||
self._unlink_users(cr, uid, ids, context=context)
|
||||
# link new records
|
||||
self._link_users(cr, uid, ids, user_ids, context=context)
|
||||
return True
|
||||
|
||||
#------------------------------------------------------
|
||||
# Addon API
|
||||
#------------------------------------------------------
|
||||
|
||||
def get_needaction_user_ids(self, cr, uid, ids, context=None):
|
||||
""" Returns the user_ids that have to perform an action
|
||||
:return: dict { record_id: [user_ids], }
|
||||
"""
|
||||
return dict.fromkeys(ids, [])
|
||||
|
||||
def create(self, cr, uid, values, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
needact_table_obj = self.pool.get('ir.needaction_users')
|
||||
# perform create
|
||||
obj_id = super(ir_needaction, self).create(cr, uid, values, context=context)
|
||||
obj_id = super(ir_needaction_mixin, self).create(cr, uid, values, context=context)
|
||||
# link user_ids
|
||||
needaction_user_ids = self.get_needaction_user_ids(cr, uid, [obj_id], context=context)
|
||||
self._link_users(cr, uid, [obj_id], needaction_user_ids[obj_id], context=context)
|
||||
needact_table_obj.create_users(cr, uid, [obj_id], self._name, needaction_user_ids[obj_id], context=context)
|
||||
return obj_id
|
||||
|
||||
def write(self, cr, uid, ids, values, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
needact_table_obj = self.pool.get('ir.needaction_users')
|
||||
# perform write
|
||||
write_res = super(ir_needaction, self).write(cr, uid, ids, values, context=context)
|
||||
write_res = super(ir_needaction_mixin, self).write(cr, uid, ids, values, context=context)
|
||||
# get and update user_ids
|
||||
needaction_user_ids = self.get_needaction_user_ids(cr, uid, ids, context=context)
|
||||
for id in ids:
|
||||
self._update_users(cr, uid, [id], needaction_user_ids[id], context=context)
|
||||
needact_table_obj.update_users(cr, uid, [id], self._name, needaction_user_ids[id], context=context)
|
||||
return write_res
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
# unlink user_ids
|
||||
self._unlink_users(cr, uid, ids, context=context)
|
||||
needact_table_obj = self.pool.get('ir.needaction_users')
|
||||
needact_table_obj.unlink_users(cr, uid, ids, self._name, context=context)
|
||||
# perform unlink
|
||||
return super(ir_needaction, self).unlink(cr, uid, ids, context=context)
|
||||
return super(ir_needaction_mixin, self).unlink(cr, uid, ids, context=context)
|
||||
|
||||
#------------------------------------------------------
|
||||
# Need action API
|
||||
#------------------------------------------------------
|
||||
|
||||
@classmethod
|
||||
def needaction_get_record_ids(cls, cr, uid, model_name, user_id, limit=80, context=None):
|
||||
"""Given a model and a user_id
|
||||
def needaction_get_record_ids(self, cr, uid, user_id, limit=80, context=None):
|
||||
"""Given the current model and a user_id
|
||||
get the number of actions it has to perform"""
|
||||
if context is None:
|
||||
context = {}
|
||||
need_act_obj = pooler.get_pool(cr.dbname).get('ir.needaction_users_rel')
|
||||
need_act_ids = need_act_obj.search(cr, uid, [('res_model', '=', model_name), ('user_id', '=', user_id)], limit=limit, context=context)
|
||||
return map(itemgetter('res_id'), need_act_obj.read(cr, uid, need_act_ids, context=context))
|
||||
needact_table_obj = self.pool.get('ir.needaction_users')
|
||||
needact_table_ids = needact_table_obj.search(cr, uid, [('res_model', '=', self._name), ('user_id', '=', user_id)], limit=limit, context=context)
|
||||
return map(itemgetter('res_id'), needact_table_obj.read(cr, uid, needact_table_ids, context=context))
|
||||
|
||||
@classmethod
|
||||
def needaction_get_action_count(cls, cr, uid, model_name, user_id, limit=80, context=None):
|
||||
"""Given a model and a user_id
|
||||
def needaction_get_action_count(self, cr, uid, user_id, limit=80, context=None):
|
||||
"""Given the current model and a user_id
|
||||
get the number of actions it has to perform"""
|
||||
if context is None:
|
||||
context = {}
|
||||
need_act_obj = pooler.get_pool(cr.dbname).get('ir.needaction_users_rel')
|
||||
return need_act_obj.search(cr, uid, [('res_model', '=', model_name), ('user_id', '=', user_id)], limit=limit, count=True, context=context)
|
||||
needact_table_obj = self.pool.get('ir.needaction_users')
|
||||
return needact_table_obj.search(cr, uid, [('res_model', '=', self._name), ('user_id', '=', user_id)], limit=limit, count=True, context=context)
|
||||
|
||||
@classmethod
|
||||
def needaction_get_record_references(cls, cr, uid, user_id, offset=None, limit=None, order=None, context=None):
|
||||
def needaction_get_record_references(self, cr, uid, user_id, offset=None, limit=None, order=None, context=None):
|
||||
"""For a given user_id, get all the records that asks this user to
|
||||
perform an action. Records are given as references, a list of
|
||||
tuples (model_name, record_id).
|
||||
This method is trans-model."""
|
||||
if context is None:
|
||||
context = {}
|
||||
need_act_obj = pooler.get_pool(cr.dbname).get('ir.needaction_users_rel')
|
||||
need_act_ids = need_act_obj.search(cr, uid, [('user_id', '=', user_id)], offset=offset, limit=limit, order=order, context=context)
|
||||
need_acts = need_act_obj.read(cr, uid, need_act_ids, context=context)
|
||||
return map(itemgetter('res_model', 'id'), need_acts)
|
||||
needact_table_obj = self.pool.get('ir.needaction_users')
|
||||
needact_table_ids = needact_table_obj.search(cr, uid, [('user_id', '=', user_id)], offset=offset, limit=limit, order=order, context=context)
|
||||
needact_records = needact_table_obj.read(cr, uid, needact_table_ids, context=context)
|
||||
return map(itemgetter('res_model', 'id'), needact_records)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -262,7 +262,7 @@ class ir_ui_menu(osv.osv):
|
|||
for menu in self.browse(cr, uid, ids, context=context):
|
||||
res[menu.id] = {}
|
||||
if menu.action and menu.action.type == 'ir.actions.act_window' and menu.action.res_model:
|
||||
menu_needaction_res = osv.osv.get_needaction_info(cr, uid, menu.action.res_model, uid, domain=menu.action.domain, context=context)
|
||||
menu_needaction_res = self.pool.get(menu.action.res_model).get_needaction_info(cr, uid, uid, domain=menu.action.domain, context=context)
|
||||
else:
|
||||
menu_needaction_res = [False, 0, ()]
|
||||
res[menu.id]['needaction_enabled'] = menu_needaction_res[0]
|
||||
|
|
|
@ -121,4 +121,4 @@
|
|||
"access_ir_mail_server_all","ir_mail_server","model_ir_mail_server",,1,0,0,0
|
||||
"access_ir_actions_todo_category","ir_actions_todo_category","model_ir_actions_todo_category","group_system",1,1,1,1
|
||||
"access_ir_actions_client","ir_actions_client all","model_ir_actions_client",,1,0,0,0
|
||||
"access_ir_needaction_users_rel","ir_needaction_users_rel all","model_ir_needaction_users_rel",,1,1,1,1
|
||||
"access_ir_needaction_users","ir_needaction_users","model_ir_needaction_users",,1,1,1,1
|
||||
|
|
|
|
@ -57,7 +57,6 @@ from lxml import etree
|
|||
import fields
|
||||
import openerp
|
||||
import openerp.netsvc as netsvc
|
||||
import openerp.pooler as pooler
|
||||
import openerp.tools as tools
|
||||
from openerp.tools.config import config
|
||||
from openerp.tools.safe_eval import safe_eval as eval
|
||||
|
@ -712,36 +711,6 @@ class BaseModel(object):
|
|||
def log(self, cr, uid, id, message, secondary=False, context=None):
|
||||
return _logger.warning("log() is deprecated. Please use OpenChatter notification system instead of the res.log mechanism.")
|
||||
|
||||
@staticmethod
|
||||
def get_needaction_info(cr, uid, model_name, user_id, limit=None, order=None, domain=False, context=None):
|
||||
"""Base method for needaction mechanism
|
||||
- see ir.needaction for actual implementation
|
||||
- if the model uses the need action mechanism
|
||||
(hasattr(model_obj, 'needaction_get_record_ids')):
|
||||
- get the record ids on which the user has actions to perform
|
||||
- evaluate the menu domain
|
||||
- compose a new domain: menu domain, limited to ids of
|
||||
records requesting an action
|
||||
- count the number of records maching that domain, that
|
||||
is the number of actions the user has to perform
|
||||
- this method returns default values
|
||||
:param: model_name: the name of the model (ex: hr.holidays)
|
||||
:param: user_id: the id of user
|
||||
:return: [uses_needaction=True/False, needaction_uid_ctr=%d]
|
||||
"""
|
||||
model_obj = pooler.get_pool(cr.dbname).get(model_name)
|
||||
if hasattr(model_obj, 'needaction_get_record_ids'):
|
||||
ids = model_obj.needaction_get_record_ids(cr, uid, model_name, user_id, limit=8096, context=context)
|
||||
if not ids:
|
||||
return (True, 0, [])
|
||||
if domain:
|
||||
new_domain = eval(domain) + [('id', 'in', ids)]
|
||||
else:
|
||||
new_domain = [('id', 'in', ids)]
|
||||
return (True, model_obj.search(cr, uid, new_domain, limit=limit, order=order, count=True), ids)
|
||||
else:
|
||||
return (False, 0, [])
|
||||
|
||||
def view_init(self, cr, uid, fields_list, context=None):
|
||||
"""Override this method to do specific things when a view on the object is opened."""
|
||||
pass
|
||||
|
@ -4897,6 +4866,34 @@ class BaseModel(object):
|
|||
get_xml_id = get_external_id
|
||||
_get_xml_ids = _get_external_ids
|
||||
|
||||
def get_needaction_info(self, cr, uid, user_id, limit=None, order=None, domain=False, context=None):
|
||||
"""Base method for needaction mechanism
|
||||
- see ir.needaction for actual implementation
|
||||
- if the model uses the need action mechanism
|
||||
(hasattr(model_obj, 'needaction_get_record_ids')):
|
||||
- get the record ids on which the user has actions to perform
|
||||
- evaluate the menu domain
|
||||
- compose a new domain: menu domain, limited to ids of
|
||||
records requesting an action
|
||||
- count the number of records maching that domain, that
|
||||
is the number of actions the user has to perform
|
||||
- this method returns default values
|
||||
:param: model_name: the name of the model (ex: hr.holidays)
|
||||
:param: user_id: the id of user
|
||||
:return: [uses_needaction=True/False, needaction_uid_ctr=%d]
|
||||
"""
|
||||
if hasattr(self, 'needaction_get_record_ids'):
|
||||
ids = self.needaction_get_record_ids(cr, uid, user_id, limit=8192, context=context)
|
||||
if not ids:
|
||||
return (True, 0, [])
|
||||
if domain:
|
||||
new_domain = eval(domain) + [('id', 'in', ids)]
|
||||
else:
|
||||
new_domain = [('id', 'in', ids)]
|
||||
return (True, self.search(cr, uid, new_domain, limit=limit, order=order, count=True, context=context), ids)
|
||||
else:
|
||||
return (False, 0, [])
|
||||
|
||||
# Transience
|
||||
def is_transient(self):
|
||||
""" Return whether the model is transient.
|
||||
|
|
Loading…
Reference in New Issue