我有一个创建表单的自定义模块。根据此表格中的答案,我正在生成订单行。用户发送此表单后,我正在使用生成的订单行中的所有产品创建销售订单。
因此,我从 JavaScript 发送了一个包含要购买的产品的 JSON:
order_data = [{product_id: 1, amount: 10, …},{product_id: 2, …}, …];
note = '';
this._rpc({
route: '/api/create_order',
params: { order_products: order_data, note: note }
}).then((data) => {
window.location = '/contactus-thank-you';
}).catch((error) => {
console.error(error);
});
Run Code Online (Sandbox Code Playgroud)
然后在 Python 中,我根据 JSON 创建销售订单:
@http.route('/api/create_order', type='json', auth='user', website=True)
def create_order(self, **kw):
uid = http.request.env.context.get('uid')
partner_id = http.request.env['res.users'].search([('id','=',uid)]).partner_id.id
order_products = kw.get('order_products', [])
note = kw.get('note', '')
order_line = []
for product in order_products:
amount = 0
if 'custom_amount' in product:
amount …
Run Code Online (Sandbox Code Playgroud)