Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

How to prevent from changing discount field?

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
groupprice
2 Replies
7106 Tampilan
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
Buang
Avatar
Emipro Technologies Pvt. Ltd.
Jawaban Terbai

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
Buang
Paulo Matos‏
Penulis

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‏
Penulis

Thank you very much chirag. You saved the day!

Avatar
Paulo Matos‏
Penulis Jawaban Terbai

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
Buang
Emipro Technologies Pvt. Ltd.

hi, can you give me your module name ?

Paulo Matos‏
Penulis

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‏
Penulis

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‏
Penulis

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‏
Penulis

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‏
Penulis

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.

Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
Not allowing sales employees to change prices
sales group price
Avatar
Avatar
1
Mar 15
6256
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
Mar 15
4592
Problem with tax included price Diselesaikan
price
Avatar
1
Jun 23
243
With odoo 16 what are the prices for iot box?
price
Avatar
Avatar
1
Des 22
4617
Field `group_display_incoterm` does not exist
group
Avatar
Avatar
1
Mar 22
3023
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik 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