İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
9353 Görünümler


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
Vazgeç
En İyi Yanıt

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
Vazgeç
Üretici En İyi Yanıt

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

Avatar
Vazgeç

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

Üretici

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

Thanks for the upvote, happy to help

En İyi Yanıt

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Mar 23
2343
1
Haz 22
3475
1
Tem 21
3117
0
Nis 16
3574
2
Şub 23
2180