I am trying to filter a field many2one with the data of another field many2one, but I get an error. I do not know how to pass the field many2one to String to be able to use it in the filter I am using odoo 12
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class avisos(models.Model):
_name = 'sistelin.avisos'
aviso = fields.Char(string="Aviso")
cliente = fields.Many2one('res.partner')
clientefin = fields.Char(string="Cliente Final")
empresa = fields.Many2one('res.users', default=lambda self:self.env.user)
precio = fields.Integer(string="Precio")
entrada = fields.Char(string="Entrada")
salida = fields.Char(string="Salida")
provincia = fields.Many2one('x_provincia', 'Provincias')
localidad = fields.Many2one('x_localidades', 'Localildades')
distancia = fields.Char(string="Distancia")
tiempo= fields.Char(string="Tiempo Desplazamiento")
descripcion = fields.Text("Trabajo realizado")
parte = fields.Binary()
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="avisos_form_view" model="ir.ui.view">
<field name="name">avisos.form.view</field>
<field name="model">sistelin.avisos</field>
<field name="arch" type="xml">
<form string="Insertar Aviso">
<group String="Datos de cliente">
<group>
<field name="aviso"/>
<field name="cliente"/>
<field name="provincia"/>
</group>
<group>
<field name="empresa"/>
<field name="clientefin"/>
<field name="localidad" domain="[('x_provincia','=',provincia)]"/>
</group>
</group>
</form>
</field>
</record>
</odoo>
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
Here's an example on how this works:
class ClassA(models.Model):
_name = 'class.a'
name = fields.Char('name')
class B(models.Model):
_name = 'class.b'
name = fields.Char('name')
domain_field_id = fields.Many2one('class.a', 'domain field')
class ClassC(models.Model):
_name = 'class.c'
name = fields.Char('name')
first_field_id = fields.Many2one('class.a', 'First')
second_field_id = fields.Many2one('class.b', 'Second')
in the xml view of the classC (in your case: avisos)
<field name="first_field_id"/>
<field name="second_field_id" domain="[('domain_field_id','=',first_field_id)]"/>
I've tried that but it gives me an error, it does not take the data
<group String="Datos de cliente">
<group>
<field name="aviso"/>
<field name="cliente" domain="[('customer','=',True)]"/>
<field name="provincia"/>
</group>
<group>
<field name="empresa"/>
<field name="clientefin"/>
<field name="localidad" domain="[('x_provincia','=',provincia)]"/>
</group>
</group>
But if I put the filter value directly if it works
<group String="Datos de cliente">
<group>
<field name="aviso"/>
<field name="cliente" domain="[('customer','=',True)]"/>
<field name="provincia"/>
</group>
<group>
<field name="empresa"/>
<field name="clientefin"/>
<field name="localidad" domain="[('x_provincia','=','Sevilla')]"/>
</group>
</group>
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