Odoo - 确认销售订单

Odoo - Confirm Sales Order

您好,我正在使用 Odoo10 并尝试在 POS 中创建销售订单,下面的代码创建了销售订单报价单。我想确认销售并创建销售订单而不是报价单。

@api.model
    def create_sales_order(self, orderline, customer_id, sign):
        sale_pool = self.env['sale.order']
        prod_pool = self.env['product.product']
        sale_line_pool = self.env['sale.order.line']
        sale_no = ''
        sale = {}
        if customer_id:
            customer_id = int(customer_id)
            sale = {'partner_id': customer_id, 
                    'partner_invoice_id': customer_id,
                    'partner_shipping_id': customer_id, 
                    'signature': sign}
            sale_id = sale_pool.create(sale)
            if sale_id:
                sale_brw = sale_id
                sale_brw.onchange_partner_id()
                #create sale order line
                for line in orderline:
                    sale_line = {}
                    if line.get('product_id'):
                        prod_rec = prod_pool.browse(line['product_id'])
                        sale_line.update({'name': prod_rec.name or False,
                                          'product_id': prod_rec.id,
                                          'product_uom_qty': line['qty'],
                                          'discount': line.get('discount'),
                                          'order_id': sale_id.id})
                        sale_line_id = sale_line_pool.create(sale_line)
                        for line in sale_line_id:
                            line.product_id_change()
        return {"name": sale_brw.name, "id": sale_brw.id } 

如何创建销售订单而不是报价单?

简答:将 state 设置为 "sale":


    sale = {'partner_id': customer_id, 
            'partner_invoice_id': customer_id,
            'partner_shipping_id': customer_id, 
            'signature': sign,
            'state': 'sale'}

销售订单和报价单保存在同一个模型(即sale.order)上,您可以通过查看其state来判断它是SO还是报价单:

state  | Meaning
-------|--------
draft  | Quotation
sent   | Quotation Sent
sale   | Sales Order
done   | Locked
cancel | Cancelled

此外,您可以查看 action_confirm 函数,它通过单击 addons/sale/models/sale.py 文件上的 确认销售 按钮触发:


    445     def action_done(self):
    446         return self.write({'state': 'done'})
...
    451     @api.multi
    452     def action_confirm(self):
    453         for order in self:
    454             order.state = 'sale'
    455             order.confirmation_date = fields.Datetime.now()
    456             if self.env.context.get('send_email'):
    457                 self.force_quotation_send()
    458             order.order_line._action_procurement_create()
    459         if self.env['ir.values'].get_default('sale.config.settings', 'auto_done_setting'):
    460             self.action_done()
    461         return True