我在奥多夫8的项目上工作。我需要在产品页面上添加字段,然后创建一个包含此字段的订单。你知道吗
更具体地说,我在产品页面上添加了开始日期字段,我可以在上面选择一个日期,但是当我点击“添加到购物车”并转到购物车页面时,产品没有我选择的日期。 我需要类似的功能,数量领域有。 下面是我用来在产品页面上显示日期字段的代码
<template id="product_quantity" inherit_id="website_sale.product">
<xpath expr="//a[@id='add_to_cart']" position="after">
<p>
<group colspan="2" col="2">
<label for="date">Rent Start Date
<input type="date" string="Rent Start Date" class="form-control" name="start_date" id="start_date" data-oe-model="ir.ui.view" data-oe-field="arch" />
</label>
</group>
</p>
</xpath>
</template>
下面是它的样子: Date field on product page 另外,我对用当前日期初始化这个字段的方法很感兴趣。你知道吗
感谢您的帮助。谢谢您!你知道吗
您需要扩展模型
sale.order
并添加一个新字段,在您的示例中称之为maybestart_date
,但请确保它在sale.order
上不存在。你知道吗你可以see an example of how to define such a field in the original Odoo v8 repo here。然后可以为该字段设置默认值see for example here。你知道吗
如果我没记错的话,} 并根据需要更新销售订单。你知道吗
Add to cart
按钮会触发路径'/shop/cart/cart_update'
上的控制器,因此您必须extend the method ^{我建议您扩展该方法,执行
super
调用as it is for example done here(这只是一个示例,以防您从未执行过此操作,当然您需要调整它),并将super的返回值保存在一个变量中,例如res = super(...)
。你知道吗在
super
之后,您更改了销售订单(您需要以某种方式获取它,或者您检查销售订单是否已经在res.qcontext
中可用(可能不会,因为parent returns a redirect),或者您通过request.website.sale_get_order()
which can be seen here获取它。你知道吗更新销售订单后,您终于
return res
。你知道吗沿着这些思路应该可以做到:
相关问题 更多 >
编程相关推荐