Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • eLearning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Información
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Services for Partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

How to prevent from changing discount field?

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
groupprice
2 Respuestas
7108 Vistas
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
Descartar
Avatar
Emipro Technologies Pvt. Ltd.
Mejor respuesta

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
Descartar
Paulo Matos‏
Autor

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

Thank you very much chirag. You saved the day!

Avatar
Paulo Matos‏
Autor Mejor respuesta

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

hi, can you give me your module name ?

Paulo Matos‏
Autor

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

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

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

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

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.

¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
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
4600
Problem with tax included price Resuelto
price
Avatar
1
jun 23
243
With odoo 16 what are the prices for iot box?
price
Avatar
Avatar
1
dic 22
4618
Field `group_display_incoterm` does not exist
group
Avatar
Avatar
1
mar 22
3024
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

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