Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    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
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

How to prevent from changing discount field?

Subscribe

Get notified when there's activity on this post

This question has been flagged
groupprice
2 Replies
7096 Views
Avatar
Paulo Matos‏

Hi all,

I need to prevent a group from changing unit price on sale order.

I have found this code, but I really do not know where to put it. On the code, "Fellow" is the group name and "permissions" is a function field.

def _check_permissions(self, cr, uid, ids, field_name, arg, context):
        res = {}
        formid = ids[0]
        group_obj = self.pool.get('res.groups')
        group_ids = group_obj.search(cr, uid, [('name','=','Fellow')])
        group_obj = group_obj.browse(cr, uid, group_ids)
        group_users = len(fellow[0].users)
        i = 0
        while i < group_users :
            if group_obj[0].users[i].id == uid :
                res[formid] = True
        i = i + i
        return res    

and

'permissions': fields.function(_check_permissions, type='char', method=True, string="Permissions"), 

'price': fields.float('price'),

and also this code

<field name="permissions" invisible="1"/>
<field name="price" attrs="{'readonly':[('permissions','=',True)]}"/>

Can you please help me on where to put each piece of code?

Paulo

 

0
Avatar
Discard
Avatar
Emipro Technologies Pvt. Ltd.
Best Answer

Hi Paulo,

Please refer the sructure of the new (custome) module as like.

1) File :  __openerp__.py : This file contains the simple parameters like name of module, depends etc. You can also copy this file from any other module and made change according your requirement.

2) File :  __init__.py : In this file you have to write down.

import sale_order.py

3) File : sale_order.py

class sale_order_line(osv.Model)

    _inherit = "sale.order.line"

    _name = "sale.order.line"

    def _check_permissions(self, cr, uid, ids, field_name, arg, context):
        res = {}
        formid = ids[0]
        group_obj = self.pool.get('res.groups')
        group_ids = group_obj.search(cr, uid, [('name','=','Fellow')])
        group_obj = group_obj.browse(cr, uid, group_ids)
        group_users = len(fellow[0].users)
        i = 0
        while i < group_users :
            if group_obj[0].users[i].id == uid :
                res[formid] = True
        i = i + i
        return res    

    _columns = {

                       'permissions': fields.function(_check_permissions, type='char', method=True, string="Permissions"), 
                       'price': fields.float('price'),

                  }

4) File : sale_order_view.xml

        <record id="inherited_view_order_form_add_permission" model="ir.ui.view">
            <field name="name">sale.order.form.add.permission</field>
            <field name="inherit_id" ref="sale.view_order_form" />
            <field name="model">sale.order</field>
            <field name="arch" type="xml">
                <field name="" position="before">
                    <field name="permissions" invisible="1" />
                    <field name="price" attrs="{'readonly':[('permissions','=',True)]}" />
                </field> 
            </field>

 

Then after just installe your new module. Thats it.

1
Avatar
Discard
Paulo Matos‏
Author

Dear chirag, Thank you very much. I just did not understood the last part "inherit it into .xml" file. I lack of knowledge on programming principles of Odoo. Is it possible for you to send me a sample _init_.py, _openerp_.py, testmodel.py and the .xml you refer? This way will be easier for me to read the code and fully understand the flow. Thank you once again

Emipro Technologies Pvt. Ltd.

hi, I have just updated my answer. According your need. Just give me up vote for this. Thanks.

Paulo Matos‏
Author

Thank you very much chirag. You saved the day!

Avatar
Paulo Matos‏
Author Best Answer

chirag,

Sorry but I still need your help.

Followed the instructions and created the module with the files. The odoo server is start with no errors on logfile and seems to everything ok. Just found an error when installing the module. It's a "RuntimeError: maximum recursion depth exceeded".

Part of the logfile:

  File "/home/openerp/openerp-7.0/server/openerp/modules/module.py", line 133, in load_module
    mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
  File "/home/openerp/openerp-7.0/my_addons/sale_order/__init__.py", line 34, in <module>
    import sale_order
  File "/home/openerp/openerp-7.0/server/openerp/modules/module.py", line 133, in load_module
    mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
  File "/home/openerp/openerp-7.0/my_addons/sale_order/__init__.py", line 34, in <module>
    import sale_order

Can you please help me identify this error?

Revied the code and instructions you sent and are all exactly as instructed.

Can you please help once again?

Regards

Paulo

 

 

0
Avatar
Discard
Emipro Technologies Pvt. Ltd.

hi, can you give me your module name ?

Paulo Matos‏
Author

chirag, I found the problem. Windows added an "py" extension to the file sales_order.py. The file was named "sales_order.py.py" No I am having a different error when installing the module. The error is: "File "/home/openerp/openerp-7.0/my_addons/permissions/__init__.py", line 34, in import sale_order File "/home/openerp/openerp-7.0/my_addons/permissions/sale_order.py", line 25 class sale_order(osv.Model) ^ SyntaxError: invalid syntax " But anyway and answering to your question: - for testing purposes the module name is "permissions" (first time it was "sale_order" but changed it to permissions - folder named permissions). - on _openerp_.py the value name is "Permissions". - According to instructions, added 2 additional files. sales_order.py and sales_order_view.xml with the exact code for each one of them. Regards

Emipro Technologies Pvt. Ltd.

ohh, I just forgot to put the ":" at the end. class sale_order(osv.Model):

Paulo Matos‏
Author

Thank you chirag. I urgently need to learn python :o) Now I have another error: "NameError: name '_check_permissions' is not defined". At the top of sale_order.py I added the code "from openerp.osv import fields, osv" and the rest of the file is exactly as you sent. I am sorry chirag...

Emipro Technologies Pvt. Ltd.

I think you are right ;). Just give four space (" ") before def _check_permissions thats it. I have also updated in my answer.

Paulo Matos‏
Author

heheheh. Indent on pyhon.. I think I read about that somewhere. It worked, but now I have another error: "ValueError The class sale_order has to have a _name attribute "

Emipro Technologies Pvt. Ltd.

I have done changes in my answer.

Paulo Matos‏
Author

Thank you very much chirag. Odoo accepted the module. But I've missing something here. I can see that the field "permissions" was added to the system (Settings - Technical - Database Structure - fields), but when I create a Sale Order with a user from the group "Fellow", the price field is still editable (price_unit instead of price on the code - 'price': fields.float('price')). When I "View fields" on developer mode I can see the field there. Perhaps it must be inherit on sale order lines and not on sales order? Any idea?

Emipro Technologies Pvt. Ltd.

hi Paulo, I have updated my answer. You are right. Today I am quite busy with R&D task so, my concentration is not here. Sorry for that.

Paulo Matos‏
Author

I am sorry being disturbing you since you are busy. The code did not worked. With your last instructions the permissions field was added to Sale Order Lines sucessfully, the Fellow group exist and when I make a sale order the user is still able to change the field price_unit on sales order lines. I can see that the default field price_unit from sales module was updated with this new price_unit field which is ok, but when I access this price unit settings (database structure / fields) I do not see the Fellow group on "Groups" on its settings. Also when I try to uninstall the module I get an error that might help on identify the problem TypeError: The model "sale.order.line" specifies an unexisting parent class "sale.order.line" You may need to add a dependency on the parent class' module.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Not allowing sales employees to change prices
sales group price
Avatar
Avatar
1
मार्च 15
6243
How to apply Field level access right to a price field which happens to be in Javascript and not in python?
user group price
Avatar
0
मार्च 15
4585
Problem with tax included price Solved
price
Avatar
1
जून 23
243
With odoo 16 what are the prices for iot box?
price
Avatar
Avatar
1
दिस॰ 22
4611
Field `group_display_incoterm` does not exist
group
Avatar
Avatar
1
मार्च 22
3022
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة 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, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

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