嗨,我正在使用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 }
如何创建不报价的销售订单?
答案 0 :(得分:0)
简短答案:将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
文件上的 Confirm Sale 按钮触发的功能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