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.

1

Website Form(Set Value for One2many)

By
Jamin Shah
on 12/16/15, 1:03 AM 435 views

Hello,


I have product line in website Form.Product Line Have 3 fields(product_id, Quantity, Specification).

Problem is how to create record of product line and attach same with current model from website form.


AFAIK One2many in website form accept only ids in list format, not (0, _, {..}) format.

Can I am missing somewhere or need to be customize the code.

Thanks!

1
Ajay Patel
On 12/16/15, 4:25 AM

yes in /website_form  One2many return a list of ids. so if you archive this type of functionality then you want to override extract_data().

like,
 

def extract_data(self, model, **kwargs):

product_ids = kwargs.pop('product_id[]', '').split(',')

quantity = kwargs.pop('quantity[]', '').split(',')

model_record = request.env['ir.model'].search([('model', '=', 'product.line')])

product_line_ids = []

line = {}

for index, product in enumerate(product_ids):

line = {

'product_id': product,

'quantity': quantity[index]

}

product_line_ids.append((0, 0, line))

data = super(Website, self).extract_data(model, * * kwargs)

if data['record']:

data['record']['product_ids'] = product_line_ids

return data


Suppose you have a multiple line on form view for product, add this list in form, for ex.

<input type="text" name="product_id[]"/>

try this it will help you. Thanks ;)

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

1 follower(s)

Stats

Asked: 12/16/15, 1:03 AM
Seen: 435 times
Last updated: 12/18/15, 7:06 AM