This question has been flagged
6 Replies
5901 Views

How can I show an editable text field in the Shopping cart ? The field is properly defined as a field.text on the Sales Order object, and is visible and editable in the Quotations and Sales Order views in the backend.

I tried entering

    <p>Enter your remarks here:</p>
    <p t-field="website_sale_order.comments" placeholder="Enter your comments here..."/>

just after the table in the 'total' thing of the Shopping Cart, but that shows only the label 'Enter your remarks here:' and no editable text field.

Avatar
Discard

do you need an editable text that the customers can use or a text from our side?

Author

The purpose of the field is that the customer can enter some additional comments to her/his order; I want to store that information in a text field on the Sales Order. So I need an editable text that the customers can use.

Best Answer

"<p t-field=..."
This is just displaying the value of the field in a paragraph, if you need the user to enter something, you need to create some kind of input or textarea in a form. And then you need to override the route to handle the additional parameter.

Note that the feature you want to create already exists, if you click on "customize" as admin during the checkout flow, you have "extra step option".

Avatar
Discard
Best Answer

I have a similar need: how to add a product attribute to the shopping cart (just below the product name)

My 2cents if it can help you.

below is the html code generated by Odoo for the comments block that is attached to the blog web pages


<?xml version="1.0"?>
<data name="Allow Comments">
<xpath expr="//ul[@id='comments-list']" position="before">
<section class="mb32 css_editable_mode_hidden">
<form id="comment" t-attf-action="/blogpost/comment" method="POST">
<input name="blog_post_id" t-att-value="blog_post.id" type="hidden"/>
<img class="img pull-left img-rounded" t-att-src="'/website/image?model=res.partner&field=image_small&id='+str(user_id.partner_id.id)" style="width: 50px; margin-right: 10px;"/>
<div class="pull-left mb32" style="width: 75%">
<textarea rows="3" name="comment" class="form-control" placeholder="Ecrire vos observations..."/>
<button type="submit" class="btn btn-primary mt8">Publier</button>
</div>
</form>
</section>
<div class="clearfix"/>
</xpath>
</data>

Avatar
Discard
Best Answer

@Bart,

I'll also be needing this for my own project.

I think your issue may be due to the fact you don't seem to be using your t-for-each's t-as attribute. Here's the code that controls the foreach loop:

 <t t-foreach="website_sale_order.website_order_line" t-as="line">

I think in your situation you need to add "line" to your t-field like this:

<p t-field="line.website_sale_order.comments" placeholder="Enter your comments here..."/>

Without seeing the rest of your custom code it's hard to say if this is definitely the problem, however from a brief look at your issue I have a feeling it is.

Check out the developer documenation here, specifically the section on loops:

https://www.odoo.com/documentation/8.0/reference/qweb.html

Please comment back if you run into any issues and i'd be glad to help.

Avatar
Discard
Author

Thank you for your remarks, but as far as I can see, your solution works for a Sales Order Line, while I need something on Sales Order level. I probably need to add some form-related xml; I'll try to see how stuff is done in the next screen of the Order Processing.