Skip to Content
Menu
This question has been flagged

I have this situation w/c i don't know what to do about it. The case is this: In class sale_order I have this definition:

...
'sched_lines' : fields.one2many('schedule.schedule','Schedule'),
'factor_lines' : fields.one2many('sale.order.factor','Factor'),

So does, in class account_invoice i also have this definition:

...
'sched_lines' : fields.one2many('schedule.schedule','Schedule'),
'factor_lines' : fields.one2many('sale.order.factor','Factor'),


Back to class sale_order i override the method manual_invoice ,

        ...
for sale_order in self.browse(cr,uid,ids,context=context):
_logger.info("\n\t\t\tFACTOR LINES IN SALE ORDER ... %s"%(str(sale_order.factor_lines)))
_logger.info("\n\t\t\tHISTORY IN SALE ORDER ... %s"%(str(sale_order.sched_lines)))
inv_id = self.pool.get('account.invoice').search(cr,uid,[('id','in',[new_inv_ids]),('origin','=',sale_order.name)])

factor_list = self.pool.get('sale.order.factor').search(cr,uid,[('invoice_id','=',inv_id[0])])
_logger.info("\n\t\t\tfactor_list...%s"%(str(factor_list)))
factor_lines1 = [factors.id for factors in self.pool.get('sale.order.factor').browse(cr,uid,factor_list,context=context)]
_logger.info("\n\t\t\tfactor_lines1...%s"%(str(factor_lines1)))

# cr.execute('select id from sale_order_factor where invoice_id = %s', (tuple(inv_id)))
#---------------- factor_lines1 = map(lambda x: x[0], cr.fetchall())
# factor_lines1 = [(1,0,[factors.id for factors in sale_order.factor_lines])]
#--- _logger.info("\n\t\t\tfactor_lines1...%s"%(str(factor_lines1)))

self.pool.get('account.invoice').write(cr,uid,inv_id,{
'sched_lines': [(6,0,[sched.id for sched in sale_order.sched_lines])],
'factor_lines': [(6,0,[factor.id for factor in sale_order.factor_lines])],#factor_lines1
}

what i can't understand is that this statement "[(6,0,[factor.id for factor in sale_order.factor_lines])]" does not work. When i view the invoice it has not populated. It's source, that is the factor_lines in sale_order, is not empty. While this statement "[(6,0,[sched.id for sched in sale_order.sched_lines])]" works fine. What's inside in sched_lines from sale_order is being carried fine. Does anyone can point out what's the missing, if there is any, in my code? I am really stuck in this.


Any help is very much appreciated.

Avatar
Discard
Best Answer

Hi Anirudh Lou,

Wrong syntax followed,

Here is the solution : (Add Many2one field in both the relational model which is being used as one2many

_name = 'your.model.name'
'sched_lines' : fields.one2many('schedule.schedule','current_model_id', 'Schedule')

'factor_lines' : fields.one2many('sale.order.factor', 'current_model_id','Factor'),

#instead of current_model_id you can write your own model name where fields are defined.

Than add many2one fields:

class sale_order_factor(models.Model):

    _name = 'sale.order.factor'

    current_model_id = fields.Many2one('your.model.name', "Main Current Model")

#same as for other one2many field.

Hope this will help

Rgds,

Anil

Avatar
Discard
Author

Yeah, thanks a lot. I also noticed it when i opened my project in inspecting what are my fields difinitions. Thanks again. :)

Author Best Answer

Okay, I got it there is nothing wrong about the code. The mistake is on my declaration of

 'factor_lines' : fields.one2many('sale.order.factor','Factor'), 

Instead of pointing it to it's counter part (many2one) in class sale_order_factor. It point to different class. By the way, i forgot that my declaration above is not correctly set as seen on the body part of this question, perhaps typo error.


Avatar
Discard
Related Posts Replies Views Activity
1
Aug 15
6731
2
Mar 24
9832
2
Aug 21
12284
5
Aug 20
6377
1
Dec 19
4416