openerp - how to return domain on onchange? -
what need once select patient_id
namelab
of patient
when patient
== patient_id
appear
class labinvoice (models.model): _name = "lab.invoice" name = fields.char(string='invoice reference', default=lambda self: _('new'), store=true) patient_id = fields.many2one(string='patient',comodel_name='medical.patient',required=true, store=true ) order_line = fields.one2many('lab.order.line', 'order_id', string='order lines', copy=true, ) namelab = fields.many2one('medical.lab.patient',related='order_line.namelab',string='name lab', store=true) patient = fields.many2one('medical.patient',related='order_line.patient',string='name patient', store=true, readonly=true )
class laborderline(models.model): _name = 'lab.order.line' _description = 'labs order line' name = fields.text(string='description', required=true) order_id = fields.many2one('lab.invoice', string='invoice reference', required=true, ondelete='cascade', index=true, copy=false) namelab = fields.many2one( string='lab', comodel_name='medical.lab.patient', required=true, ondelete='cascade', ) patient= fields.many2one( 'medical.patient', string='patient', related='namelab.patient_id', readonly=true, required=true, )
<page string="order lines"> <field name="order_line" mode="tree,kanban" > <tree editable="bottom" > <field name="namelab" /> <field name="patient" /> <field name="doctor_id"/> <field name="test_prix"/> <field name="test_type_id" /> <field name="invoice_status"/> <field name="state" /> </tree>
i tried onchange in vain
@api.onchange('patient_id') def onchange_patient_id(self): if self.patient_id: self.order_line = false return {'domain':{'namelab':[('namelab.patient','=',self.patient_id.id)]}}
you need use domain
on field definition in xml.
<field name="namelab" domain="[('patient', '=', patient)]"/>
Comments
Post a Comment