Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
9513 Lượt xem


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'

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhấ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'})
])
Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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

Tác giả

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

Thanks for the upvote, happy to help

Câu trả lời hay nhấ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!    



Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 3 23
2530
1
thg 6 22
3659
1
thg 7 21
3335
0
thg 4 16
3710
2
thg 2 23
2408