Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to create records before load the form view on new record in odoo?

By
Mariano DAngelo
on 9/3/15, 11:08 PM 515 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'

2

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 9/4/15, 12:16 AM

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'})
])
0
Mariano DAngelo
On 9/4/15, 12:25 AM

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

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

Axel Mendoza
on 9/4/15, 12:46 AM

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

Mariano DAngelo
on 9/4/15, 1:07 AM

Thanks for the upvote, happy to help

Axel Mendoza
on 9/4/15, 1:08 AM
0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 9/4/15, 1:00 AM

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!    



Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 9/3/15, 11:08 PM
Seen: 515 times
Last updated: 9/4/15, 1:07 AM