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.

0

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

By
Anirudh Lou
on 8/4/15, 9:33 PM 501 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)
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

0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


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

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

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

1 follower(s)

Stats

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