我想在确认销售后在odoo website_sale中生成草稿,所以我继承了控制器,这里是代码
@http.route(['/shop/confirmation'], type='http', auth="public", website=True)
def payment_confirmation(self, **post):
sale_order_id = http.request.session.get('sale_last_order_id')
if sale_order_id:
order = http.request.env['sale.order'].sudo().browse(sale_order_id)
# here I want to create a draft invoice
return http.request.render("website_sale.confirmation", {'order': order})
else:
return http.request.redirect('/shop')
问题是:如何从订单中创建发票草稿?
答案 0 :(得分:0)
两天后我找到了解决方案,这是我的解决方案
@http.route(['/shop/confirmation'], type='http', auth="public", website=True)
def payment_confirmation(self, **post):
sale_order_id = http.request.session.get('sale_last_order_id')
if sale_order_id:
order = http.request.env['sale.order'].sudo().browse(sale_order_id)
for line in order.order_line:
line.qty_to_invoice = line.product_uom_qty
order.action_invoice_create()
return http.request.render("website_sale.confirmation", {'order': order})
else:
return http.request.redirect('/shop')