从 odoo 网站点击按钮存储数据

Store data on button click from odoo website

我想将数据从odoo 网页存储到odoo 数据库中。我已经从 odoo 网站构建器创建了一个新页面。它有几个输入字段和一个提交按钮。单击提交按钮后,我想将该字段的数据存储到数据库中的 table 中。 Odoo 文档只讲述了如何从数据库中读取数据到网页中,而没有讲述如何将数据从网页中存储到数据库中。有人知道怎么做吗?

下面是我的代码:

控制器:

@http.route('/tasks/clocktime', type='http', auth='user', website=True)
    def clock_time(self, **post):
        task_pool = request.registry['project.task']
        task_pool.attendance_action_change()
        return

模板:

<form target="_self" action="/tasks/clocktime" method="post">
    <a class="btn btn-primary a-submit">Log In/Out</a>
</form>

点击提交按钮后,您必须路由到一个方法。在该方法中,您可以使用普通的 odoo 函数(如(创建、写入))将数据存储到数据库中。
你必须使用 request.registry['model.name'].method(......)
其中方法 create/write 基于要求
我正在粘贴 website_sale 模块中的示例代码,它将数据写入 sale_order 模型

@http.route(['/shop/payment/transaction/<int:acquirer_id>'], type='json', auth="public", website=True)
    def payment_transaction(self, acquirer_id):
        cr, uid, context = request.cr, request.uid, request.context
        transaction_obj = request.registry.get('payment.transaction')
        order = request.website.sale_get_order(context=context)

        if not order or not order.order_line or acquirer_id is None:
            return request.redirect("/shop/checkout")

        assert order.partner_id.id != request.website.partner_id.id

        # find an already existing transaction
        tx = request.website.sale_get_transaction()
        if tx:
            if tx.state == 'draft':  # button cliked but no more info -> rewrite on tx or create a new one ?
                tx.write({
                    'acquirer_id': acquirer_id,
                    'amount': order.amount_total,
                })
            tx_id = tx.id
        else:
            tx_id = transaction_obj.create(cr, SUPERUSER_ID, {
                'acquirer_id': acquirer_id,
                'type': 'form',
                'amount': order.amount_total,
                'currency_id': order.pricelist_id.currency_id.id,
                'partner_id': order.partner_id.id,
                'partner_country_id': order.partner_id.country_id.id,
                'reference': order.name,
                'sale_order_id': order.id,
            }, context=context)
            request.session['sale_transaction_id'] = tx_id

        # update quotation
        request.registry['sale.order'].write(
            cr, SUPERUSER_ID, [order.id], {
                'payment_acquirer_id': acquirer_id,
                'payment_tx_id': request.session['sale_transaction_id']
            }, context=context)

        return tx_id