【问题标题】:How to get values from Website <textarea> in Odoo?如何从 Odoo 中的网站 <textarea> 获取值?
【发布时间】:2017-06-01 18:35:50
【问题描述】:

我已使用以下代码在网站支付 (/shop/payment) 屏幕中成功添加了 textarea。

<template id="payment_notes" name="PO" inherit_id="website_sale.payment">
    <xpath expr="//div[@id='payment_method']" position="after">
        <div class="mt32" method="post">
            <textarea type="textarea" rows="5" name="po_notes" style="height:100px;width:800px" placeholder="Terms and conditions..."/>
        </div>
    </xpath>
</template>

到目前为止我尝试了什么?

@http.route('/shop/payment/validate', type='http', auth="public", website=True)
def payment_validate(self, transaction_id=None, sale_order_id=None, **post):
    print "\n=======res=paymentvalidate====", request.session.get('po_notes'), post.get('po_notes')
    ######
    ######

我没有,没有

我的问题是:

我怎样才能获得下一级的价值/shop/payment/validate

【问题讨论】:

  • 你想达到什么目的?
  • @AtulArvind,我想向销售订单发送备注。不是从结帐屏幕,而是在问题中提到的付款屏幕。

标签: python openerp odoo-9 openerp-8 odoo-website


【解决方案1】:

如果您在提交表单时想要控制器内的任何 html 控件的数据,那么您必须为每个控件提供一个类“表单控件”。因此,只需在您的 textarea 控件中添加 class='form-control' 即可。

还看到您的控件不在 html 表单内。您必须将控件放在将要提交的表单中,并且控制器将要调用。所以,你必须把你的控制放在你想得到的表格里。以下只是我们的一个想法。

<template id="payment_notes" name="PO" inherit_id="website_sale.payment">
    <xpath expr="//div[@id='payment_method']/div[@class='col-sm-12']/form" position="inside">
        <div class="mt32">
            <textarea type="textarea" rows="5" name="po_notes" style="height:100px;width:800px" class="form-control" placeholder="Terms and conditions..."/>
        </div>
    </xpath>
</template>

希望对你有帮助。

【讨论】:

  • 感谢您的努力。我已经按照您建议的代码完成了,但仍然没有给我。你能用 .py 代码指导我吗?
【解决方案2】:

.......模板........

<template id="shopping_note" inherit_id="website_sale.checkout" name="Shopping Note">
   <xpath expr="//a[@href='/shop/cart']" position="before">
     <div class="mt16 mb16">
         <label>My Notes</label>
         <input name="note" class='form-control' type="text" placeholder="Note about your order..." t-att-value="checkout.get('note')"/>
     </div>
   </xpath>
</template>

...派......

def checkout_form_save(self, checkout):
    order = request.website.sale_get_order(force_create=1, context=request.context)
    if checkout.get('note'):
        order.write({'note': checkout.get('note')})
    return super(WebsiteSale, self).checkout_form_save(checkout=checkout)

def checkout_values(self, data=None):
    res = super(WebsiteSale, self).checkout_values(data=data)
    checkout = res.get('checkout',{})
    order = request.website.sale_get_order(force_create=1, context=request.context)
    if not data:
        checkout.update({'note': order and order.note or None})
    else:
        checkout.update({'note': data and data.get('note') or None})
    return res

【讨论】:

  • 感谢您的回答。看来您的答案将在结帐屏幕上起作用。我正在处理付款屏幕。让我尝试在付款屏幕中使用您建议的代码。
  • 您的回答不能解决我的问题。在我的问题中,您可能会看到,我正在处理付款屏幕,而不是结帐屏幕。仍然没有给我。
猜你喜欢
  • 1970-01-01
  • 2019-09-27
  • 2020-07-26
  • 2014-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-28
相关资源
最近更新 更多