2017-06-23 20 views
10

मैं odoo 10 enterpeise का उपयोग कर रहा हूं। मैं विशिष्ट उपयोगकर्ताओं को बटन नहीं दिखाना चाहता हूं जो समूह में नहीं हैं क्योंकि समूह में कई उपयोगकर्ता होंगे और मैं केवल नीचे दिए गए बटन को दिखाना चाहता हूं, जिसके पास ऑब्जेक्ट को अस्वीकार/स्वीकृति देने का पूर्वाग्रह है। यहाँ बटनओडू - विशिष्ट उपयोगकर्ता के लिए छुपाएं बटन

<xpath expr="//sheet" position="before"> 
      <header> 
      <button name="update_approve" attrs="{'invisible':[('first_approve', '=', uid)]}" string="Approve" type="object" class="oe_highlight"/> 
       <button name="update_reject" attrs="{'invisible':[('second_approve', '=', uid)]}" string="Reject" type="object" class="btn-danger"/> 
      </header> 
     </xpath> 

मैं uid का उपयोग कर ऐसा करने की कोशिश की है, लेकिन uid एक्सएमएल में उपलब्ध नहीं है

first_approve और second_approve अपने मॉडल में खेतों आधारित मैं केवल उन करने के लिए बटन दिखाना चाहते हैं, जिस पर कर रहे हैं जो first_approve/second_approve

उत्तर

1

में असाइन किया गया है, मैंने यह कोशिश नहीं की है, मुझे उम्मीद है कि यह काम करेगा।

चीजों में से एक क्षेत्र का उपयोग करने के लिए मुझे पता है कि फ़ील्ड को फॉर्म में ध्यान दिया जाना चाहिए। मुझे नहीं पता कि फ़ॉर्म में उपयोगकर्ता आईडी का मूल्य कैसे प्राप्त करें। लेकिन यदि uid या user जैसा कोई छोटा नहीं है, तो आप इसके आसपास काम कर सकते हैं, बस res.users पर m2o फ़ील्ड बनाएं, इस फ़ील्ड को स्टोर = गलत के साथ गणना करें।

# by default store = False this means the value of this field 
    # is always computed. 
    current_user = fields.Many2one('res.users', compute='_get_current_user') 

    @api.depends() 
    def _get_current_user(self): 
     for rec in self: 
      rec.current_user = self.env.user 
     # i think this work too so you don't have to loop 
     self.update({'current_user' : self.env.user.id}) 

और आप इस फॉर्म का उपयोग अपने फॉर्म में कर सकते हैं।

<xpath expr="//sheet" position="before"> 
       <header> 
       <!-- fin a good place for the field if i make the header look ugly --> 
       <!-- make invisible --> 
       <field name="current_user" invisible="1"/> 
                        <!-- hope it work like this --> 
       <button name="update_approve" attrs="{'invisible':[('first_approve', '=', current_user)]}" string="Approve" type="object" class="oe_highlight"/> 
       <button name="update_reject" attrs="{'invisible':[('second_approve', '=', current_user)]}" string="Reject" type="object" class="btn-danger"/> 
       </header> 
    </xpath> 

मेरी अंग्रेजी के लिए खेद है।

1

मुझे समझा है कि आपके पास उन उपयोगकर्ताओं की एक निश्चित सूची है जो स्वीकृति देने में सक्षम होंगे और उन उपयोगकर्ताओं की अन्य निश्चित सूची जो अस्वीकार करने में सक्षम होंगे। कुछ उपयोगकर्ताओं को होने के बावजूद, मैं दो समूह बनाने के साथ अपने बटन पर groups विशेषता का प्रयोग करेंगे, लेकिन अगर फिर भी आप उनके लिए समूहों की एक जोड़ी बनाने के लिए नहीं करना चाहते हैं, तो आप ऐसा कर सकते हैं:

from openerp import models, api 
import json 
from lxml import etree 

FIRST_APPROVE = [] # Fill this list with the IDs of the users who can update approve 
SECOND_APPROVE = [] # Fill this list with the IDs of the users who can update reject 

class YourClass(models.Model): 
    _inherit = 'your.class' 

    def update_json_data(self, json_data=False, update_data={}): 
     ''' It updates JSON data. It gets JSON data, converts it to a Python 
     dictionary, updates this, and converts the dictionary to JSON data 
     again. ''' 
     dict_data = json.loads(json_data) if json_data else {} 
     dict_data.update(update_data) 
     return json.dumps(dict_data, ensure_ascii=False) 

    def set_modifiers(self, element=False, modifiers_upd={}): 
     ''' It updates the JSON modifiers with the specified data to indicate 
     if a XML tag is readonly or invisible or not. ''' 
     if element is not False: # Do not write only if element: 
      modifiers = element.get('modifiers') or {} 
      modifiers_json = self.update_json_data(
       modifiers, modifiers_upd) 
      element.set('modifiers', modifiers_json) 

    @api.model 
    def fields_view_get(self, view_id=None, view_type='form', toolbar=False, 
         submenu=False): 
     res = super(YourClass, self).fields_view_get(
      view_id=view_id, view_type=view_type, toolbar=toolbar, 
      submenu=submenu) 

     doc = etree.XML(res['arch']) 

     if view_type == 'form': 
      if self.env.uid in FIRST_APPROVE: 
       upd_approve_btn_search = doc.xpath("//button[@name='update_approve']") 
       upd_approve_btn = upd_approve_btn_search[0] \ 
        if upd_approve_btn_search else False 
       if upd_approve_btn: 
        self.set_modifiers(upd_approve_btn, {'invisible': False, }) 

      if self.env.uid in SECOND_APPROVE: 
       upd_reject_btn_search = doc.xpath("//button[@name='update_reject']") 
       upd_reject_btn = upd_reject_btn_search[0] \ 
        if upd_reject_btn_search else False 
       if upd_reject_btn: 
        self.set_modifiers(upd_reject_btn, {'invisible': False, }) 

     res['arch'] = etree.tostring(doc) 
     return res 

FIRST APPROVE और SECOND_APPROVE उस स्थिति में होगा जिसमें आपको उन उपयोगकर्ताओं के निश्चित आईडीएस को पेश करना होगा जो संबंधित कार्रवाई कर सकते हैं (उदाहरण के लिए: FIRST APPROVE = [2, 7, 9])।

YourClass वह वर्ग होना चाहिए जिसमें आपने अपने बटनों की विधियां घोषित की हैं (जिसमें आपने update_approve और update_reject घोषित किया है)।

महत्वपूर्ण: इस कोड के साथ, अपने बटन क्योंकि XML कोड लोड करने के बाद, fields_view_getinvisible मान ओवरराइट 0.

यह स्थापित करने के लिए होगा हमेशा (लिखना अपने XML दृश्य पर invisible="1") अदृश्य होना चाहिए, अपने उद्देश्य को प्रबंधित करने का एक असामान्य तरीका है, लेकिन दुर्भाग्य से मुझे लगता है कि यदि आप समूह बनाना नहीं चाहते हैं तो यह सबसे आसान है। मुझे उम्मीद है कि यह आपको और अन्य उपयोगकर्ताओं की मदद करेगा!

संबंधित मुद्दे