Skip to Content
Menu
This question has been flagged


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)
sched_obj.create(cr,uid,{
"regular_date" : date.strftime('%Y-%m-%d'),
"seq" : seq,
}
i += 1
seq += 1
return True

...
installment()

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

 

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

Avatar
Discard
Best Answer

Hello,

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

Thanx

Avatar
Discard
Related Posts Replies Views Activity
2
Dec 19
3489
3
Aug 15
21428
1
Mar 15
5292
0
Feb 16
2225
2
Aug 15
5866