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

Calling field in method of another object

Suscribirse

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

Se marcó esta pregunta
inheritselfobjectsself.env.search
1 Responder
8135 Vistas
Avatar
MatheusF

I created a field of type Boolean 'check_barcode' in the stock.config.settings object. The intent of this field is as follows if it is marked as true it would have entered a method that is in another inherited object. The problem is that my self.env is not bringing the check_barcode field (I think it's not making the stay). 


How to call the check_barcode field in the def calculate_checksum method?


field.py

class StockSettings(models.TransientModel):

    _inherit = 'stock.config.settings'

    check_barcode = fields.Boolean(string='check_barcode')


product.py

class ProductTemplate(models.Model):

    _inherit = "product.template"

    @api.onchange('barcode')

    def calculate_checksum(self):

            #if self.env.user.company_id.product_ids.compute(self.company_id.check_barcode, self.product_ids):

            #if self.env['res.config.settings'].check_barcode:                                    #.company_id.product_ids.compute(self.company_id.check_barcode, self.product_ids):

        if self.check_barcode == 'True':

            if self.barcode:

                barcode = self.barcode[:12]

                if len(barcode) < 12:

                    barcode = barcode.ljust(12, '0')



                sum_ = lambda x, y: int(x) + int(y)

                evensum = reduce(sum_, barcode[::2])

                oddsum = reduce(sum_, barcode[1::2])

                digit = (10 - ((evensum + oddsum * 3) % 10)) % 10

                self.write(

                    {

                        'barcode': barcode + str(digit)

                    }

            )

            else:

                return False






0
Avatar
Descartar
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Mejor respuesta

Hi,

You can update your field.py file like this,

class StockSettings(models.TransientModel):
_inherit = 'stock.config.settings'

check_barcode = fields.Boolean(string='check_barcode')

@api.multi
def set_check_barcode(self):
""" saving the values to ir.values """
IrValues = self.env['ir.values']
IrValues.set_default('stock.config.settings', 'check_barcode', self.check_barcode)


Then in the calculate_checksum function, you can get the value of the check_barcode like this,

ir_values = self.env['ir.values']
check_barcode = ir_values.get_default('stock.config.settings', 'check_barcode')


Now your code will be like this,

class ProductTemplate(models.Model):
_inherit = "product.template"

@api.onchange('barcode')
def calculate_checksum(self):
ir_values = self.env['ir.values']
check_barcode = ir_values.get_default('stock.config.settings', 'check_barcode')


Thanks

0
Avatar
Descartar
MatheusF
Autor

I made the update but it still gives error : [ in calculate_checksum

if self.check_barcode == 'True':

AttributeError: 'product.template' object has no attribute 'check_barcode' ]

Is this the correct syntax?

@api.onchange('barcode')

def calculate_checksum(self):

ir_values = self.env['ir.values']

check_barcode = ir_values.get_default('stock.config.settings', 'check_barcode')

if self.check_barcode == 'True':

Cybrosys Techno Solutions Pvt.Ltd

In the product.template model there is no field check_barcode, so change self.check_barcode to self.barcode

¿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
self search based on field Resuelto
self self.env.search
Avatar
Avatar
Avatar
2
feb 23
13203
Using self.env to go over all module record and create new record in another module Resuelto
self loop self.pool.get self.env.search
Avatar
Avatar
2
ene 19
15742
How to do Prototpye inherit in odoo
inherit
Avatar
Avatar
Avatar
Avatar
Avatar
4
mar 24
4438
Inheritance for account.financial.report model?
inherit
Avatar
Avatar
1
oct 23
6418
Difference between_inherit (no _name property) and _inherit (_name property value same as _inherit) ?
inherit
Avatar
Avatar
1
jun 22
7692
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