Skip to Content
Menu
This question has been flagged
4 Replies
8355 Views


I have the following models:

class Order(models.Model):
_name = 'discount_order.order'
partner_id = fields.Many2one('res.partner','Cliente',required=True)
order_lines_ids = fields.One2many('discount_order.order_line', 'order_id', string="Lineas")
obs = fields.Text('Comentarios y observaciones')
class Order_line(models.Model):
_name = 'discount_order.order_line'
order_id = fields.Many2one('discount_order.order', string="Order")
cat_id = fields.Many2one('product.category')
disc_ask = fields.Float('Descuento solicitado')
obs = fields.Char('Comentarios por linea')

I need to create 1 'order_line' for each 'product.category' record, when the user press the new button on the form view. So the new 'order object', already has assigned 'order_lines_ids'

Avatar
Discard
Best Answer

What you should really wanna do is that the new record display some data in the field order_line without having to be saved. That is named in Odoo as defaults and used to fill your new record before displayed in a form and is a data that you could discard in any moment without saving it. Your field could be defined to have defaults like this:

order_lines_ids = fields.One2many('discount_order.order_line', 'order_id', string="Lineas", default=[
    (0,0,{'order_id': 1, 'cat_id':1, 'disc_ask': 10.0, 'obs': 'comment'}),
    (0,0,{'order_id': 2, 'cat_id':2, 'disc_ask': 20.0, 'obs': 'comment2'})
])
Avatar
Discard
Author Best Answer

The records are not static, it could be a function? for each category in 'product.category' ?

Avatar
Discard

yes, the default could be a function, check the docs but the function need to return something like that

Author

thanks Axel! I hate the docs. I'm new and it's not very complete

Thanks for the upvote, happy to help

Best Answer

Mariano,

you can override default_get function of discount_order.order and in that :

res = super(order, self).default_get(cr, uid, ids, fields, context)
res.update({'default_discount_order.order' : [(0, 0, {'cat_id':1, 'disc_ask': 10.0, 'obs': 'obs'})]})

return res

This will add a order line in your order form and while saving the record, it will also be saved....

Hope it helps!    



Avatar
Discard
Related Posts Replies Views Activity
2
Mar 23
1324
1
Jun 22
2158
1
Jul 21
1708
0
Apr 16
2728
2
Feb 23
675