Odoo Help


How to set parent_id while creating it's child on on_change method?

Anirudh Lou
on 8/4/15, 9:33 PM 950 views

Does anyone who knows how to set parent_id while creating it's child on onchange method? The case is this, i have my class installment and installment_schedule. These are some of its definition:

    class installment(orm.Model):
_name = 'installment'
_columns = {
'date_start' : fields.date('Date Start'),
'date_end' : fields.date('Date End'),
'factor' : fields.function(_get_factor,.....),
'child_ids': fields.one2many('installment.schedule','parent_id','Schedule'),

def on_change_fields(self, cr, uid, ids, d_start, d_end, factor, context=None):
i = seq = 0
range = 24
sched_obj = self.pool.get('installment.schedule')
while seq < range:
while i < factor:
date = datetime.strptime(date_start, '%Y-%m-%d') + relativedelta(months=+i)
"regular_date" : date.strftime('%Y-%m-%d'),
"seq" : seq,
i += 1
seq += 1
return True


class installment_schedule(orm.Model):
_columns = {
'parent_id' : fields.many2one('installment','Installment'),
'regular_date' : fields.date('Regular Date'),
'seq' : fields.integer('Sequence'),


What i want is whenever that three fields (in installment class) are being change i also want to populate the installment_schedule class and at the same time show it on my installement_view.xml.

Any help/suggestion/recommendation is highly appreciated

--Ahmed M.Elmubarak--

Ahmed M.Elmubarak
On 8/5/15, 3:35 AM


Just small question, why you're putting the create method in an onchage_funciton ? 

this means that whenever the user make a change this will create a new record, so unnecessary records will be created if the user make some new changes at the same time ...
I think it is make scenes if you put your create method in the write function [overriding], so every time the user clicks the save button and there is  changes on some fields a new record will be created ...

I hope you got my point ..


About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 8/4/15, 9:33 PM
Seen: 950 times
Last updated: 8/5/15, 3:35 AM