Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
4 Risposte
9387 Visualizzazioni


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
Abbandona
Risposta migliore

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
Abbandona
Autore Risposta migliore

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

Avatar
Abbandona

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

Autore

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

Thanks for the upvote, happy to help

Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
mar 23
2389
1
giu 22
3507
1
lug 21
3146
0
apr 16
3601
2
feb 23
2213