Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Use default_get with field.related and get ID from parent.

By
Francisco Martínez
on 6/25/13, 3:43 PM 3,187 views

Hi Again,

I have a parent TABLE:

_name = 'sat.incidencias'
_columns = {
    'id': fields.integer('ID', readonly=True),
    'incidencia' : fields.char('Incidencia', size=256, required=True, help="Descripcion de la incidencia"),
    'objeto' : fields.char('Producto', size=256, required=True),
    'fecha' : fields.datetime('Fecha', required=True),
    'previo' : fields.text('Diagnostico Previo', required=False),
    'diagnostico' : fields.text('Diagnostico final', required=False),
    'estado' : fields.selection((('a', 'A LA ESPERA'),('d','DIAGNOSIS'), ('p','PRESUPUESTADO'), ('r','EN PROCESO'), ('e','ENTREGAR'), ('t','TERMINADO')), 'Estado'),
    'urgente' : fields.boolean('Urgente'),
    'partner_id': fields.many2one('res.partner', 'Cliente', ondelete='cascade'),
    'fecha_prevista' : fields.datetime('Fecha prevista', required=False, help="Fecha prevista de finalizacion"),
    'trabajos_realizar' : fields.text('Trabajos a realizar', required=False, help="Especificar los trabajos a realizar"),
    'trabajos_id': fields.one2many('sat.trabajos', 'incidencia_id', 'Trabajos realizados'),
    'presupuesto_id': fields.one2many('sat.presupuestos', 'incidencia_id', 'Presupuestos'),
    'total_presupuestos': fields.function(_total_presupuestos, type='float', method=True, store=False, string='Presupuestado'),

    }

And this is the child:

_name = 'sat.presupuestos'
_columns = {
            'incidencia_id': fields.many2one('sat.incidencias', 'Incidencia'),
            'wpartner_id': fields.related('incidencia_id', 'partner_id', type="many2one", relation="res.partner", string="Cliente Incidencia", store=False), # Obtiene el Cliente de la incidencia.
            'presupuesto': fields.many2one('sale.order', 'Presupuesto', ondelete='cascade', domain="[('partner_id','=',wpartner_id)]"),  # FILTRADO con el cliente actual.
            'concepto': fields.char('Concepto', size=128, required=True),
            'fecha': fields.date('Fecha', required=False),
            'pv_sin_impuestos': fields.float('Precio Base', digits=(12,2)), # Al ser un campo Monetary hay que indicar los digitos y los decimales.
            'pv_con_impuestos': fields.float('PVP+IVA' , digits=(12,2)), # Al ser un campo Monetary hay que indicar los digitos y los decimales.
            }
_defaults = {
    'wpartner_id': _default_get_wpartner,
    }
_order = 'presupuesto'

Using this function:

def _default_get_wpartner(self, cr, uid, fields, context=None):
    fields = super(presupuestos, self).default_get(cr, uid, fields, context=context)
    cr.execute('select id  from res_partner')
    data = cr.dictfetchall()
    for rec in data:
        fields['wpartner_id'] = rec.get('id', '')
    return data

The problem is when open a form with a new registersat.presupuestos, the function return wrong value ([object Object]). I need sat_presupuestos.wpartner_id = sat_incidencias.partner_id

Please help me with this problem... Thx

1

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 1/31/15, 4:21 PM

Hi Francisco,

You are having a foriegn key 'incidencias_id' in sat_presupuetos with sat_incidencias which can be used to satisfy your condition.
Default values are loaded at the first time when a record is bieng created and at that time you don't have any value for 'incidencias_id' so you cannot get partner_id too for that particular sat_incidencias record until and unless you select one(sat_incidencias record) in many2one field(incidencias_id) under sat_presupuestos form view.

so i would suggest you to go for on_change property of incidencias_id can browse its record to get the respective partner_id.

hope it will help you.

 

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 6/25/13, 3:43 PM
Seen: 3187 times
Last updated: 5/20/15, 6:43 AM