Odoo8网站将输入值从产品页面转移到购物车页面

2024-09-21 03:25:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我在奥多夫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 另外,我对用当前日期初始化这个字段的方法很感兴趣。你知道吗

感谢您的帮助。谢谢您!你知道吗


Tags: iddatadate产品grouptemplate页面product
1条回答
网友
1楼 · 发布于 2024-09-21 03:25:06

您需要扩展模型sale.order并添加一个新字段,在您的示例中称之为maybe start_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。你知道吗

沿着这些思路应该可以做到:

@http.route()
def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
    res = super(WebsiteSale, self).cart_update(product_id,
                                               add_qty, set_qty, **kw)
    order = request.website.sale_get_order()
    # update your order now 
    # ... 

    # finally return 
    return res

相关问题 更多 >

    热门问题