Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita 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
  • Proyectos
  • 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

[Odoo 10] Update view calling function from another model using button?

Suscribirse

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

Se marcó esta pregunta
functionbuttonodoo10.0
4 Respuestas
10388 Vistas
Avatar
FEDERICO LEONI

I've inherited the pos.session model with a function triggered when an index changed:

class divina_session(models.Model):        
    _inherit = 'pos.session'
  order_paid = fields.Integer('Order Paid', store=True, default='0')

@api.multi
def _write(self, vals):
res = super(divina_session, self)._write(vals)

for record in self:
record.set_data_write(vals, record)
return res
    @api.multi    
    def set_data_write(self, vals, record):        
        if vals.get('order_paid'):
            my code here

The method is used to update a whole record on another model (pos.adm).

Pos.adm has a tree view, and I would like to update the view from button, since it doesn't update automatically after db changed... However I don't know what syntax should I use on my button definition and, most important, how to trigger it on pos.session since my index (order_paid) will not change on button press. 

Any clue?

Thanks.

F.

0
Avatar
Descartar
FEDERICO LEONI
Autor

Solved (for now) calling directly the menu item from a button in my view. Simple and effective, even with a little drawback. 

<button name="%(adm_sessions_tree_view2)d" string="Update" type="action"
class="oe_highlight" attrs = "{'invisible':[('state','!=','opened')]}"/>

This will  update the view exactly like will do when calling the menu item itself (that is hidden on a 2 levels submenu), without the need to refresh the whole page. I'm still working on it to force an update manually but for now I can spend my effort on other issues I need to solve with other functions.

Avatar
FEDERICO LEONI
Autor Mejor respuesta

Solved, even if  with a not so elegant, pythonic way.

On pos.adm I created a new def since is quite easy search for the correct one (pos_session.name =is equal to pos_adm.pos_ref):

@api.multi
def _update_tree(self):

pse = self.env['pos.session'].search([('name', '=', self.pos_ref)])
pse.write({'order_paid': pse.order_paid + 1})

Since order_paid field is just an index used to trigger function is not a problem use it to force a db check.

After that I simply wrote some lines of xml for a function called by a button.

    <record id = "update" model = "ir.actions.server">
<field name = "sequence" eval = "5"/>
<field name = "name">update_session</field>
<field name = "model_id" ref = "model_pos_adm"/>
<field name = "condition">True</field>
<field name = "type">ir.actions.server</field>
<field name = "state">code</field>
<field name = "code">
pos_obj = env['pos.adm'].browse(context.get('active_id'))
pos_obj._update_tree()
</field>
</record>

The button call:

<button name="%(update)d" string="Up" type="action"
class="oe_highlight" attrs = "{'invisible':[('state','!=','opened')]}"/>

Now I have a quicker real time update on my tree view.   

0
Avatar
Descartar
Avatar
Niyas Raphy (Walnut Software Solutions)
Mejor respuesta

Hi,

Inside the write function you can achieve this, check whether Vals contains order_paid value, if so you can execute your action. First of all what is the relation between pos.session and pos.admin ? You have to get it, then if you need to execute a function in the pos.admin model, you can search the records of pos.admin model and iterate over the loop and call the function.

@api.multi
def _write(self, vals):
res = super(divina_session, self)._write(vals)
if vals.get('order_paid'):
# if there is any search filters you can give it
pos_admin_rec = self.env['pos.admin'].search([])
for pos_rec in POs_admin_rec:
#here call the function in pos.admin model
pos_rec.function_name()
return res


Thanks

1
Avatar
Descartar
FEDERICO LEONI
Autor

Niyas, thanks for your reply.

When an order is marked as paid, vals is reached two times (don't know exactly why) with tho different values. THe first time gets 'sequence_number' and the second one gets 'order_paid':

vals {'sequence_number': 17}

vals {'order_paid': 2}

Then I can intercept vals and make my call.

There is not a direct relation (nor related field) between pos.session and pos.adm.

The function on pos.session will create the basic data on pos.adm, and then the record will be populated from another function on pos.adm.

I know how to reach a function on another model (thanks anyway!) but the problem is calling by a button. I have update the thread title because was not clear.

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

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

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
api request
function api button
Avatar
0
dic 24
2005
How to open a wizard with yes or no buttons (Odoo 14) Resuelto
function button Buttons
Avatar
Avatar
Avatar
2
sept 22
9671
How To Calculate Age From Birthday Resuelto
function odoo odoo10.0
Avatar
Avatar
Avatar
Avatar
Avatar
7
sept 21
29418
How to connect button with function? Resuelto
function form inherit button
Avatar
Avatar
Avatar
3
dic 23
20879
how translate 'from openerp.osv import fields' of Odoo 9 to Odoo 10 Resuelto
function upgrading translate odoo10.0
Avatar
Avatar
Avatar
2
may 17
7951
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • 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 estar 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