Hello,
I would like, in some cases, create a draft sale.order quotation from a stock.picking.
My code is working fine except that it creates a quotation with a number and not a draft one.
What I need to change to obtain exactly what I want?
I'm using Odoo 11.
Python code:
class StockPicking(models.Model):
_inherit = 'stock.picking'
def convert_to_quotation(self):
sale_order = self.env['sale.order'].create(dict of parameters)
return {'type': 'ir.actions.act_window',
'res_model': 'sale.order',
'view_mode': 'form',
'target': 'new',
'res_id': sale_order.id}
Regards
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
Hi,
To create a draft sale.order quotation from a stock.picking, you can modify your code to set the quotation's state to draft after creating it. Here's an updated version of your code that should achieve this:
class StockPicking(models.Model):
_inherit = 'stock.picking'
def convert_to_quotation(self):
sale_order = self.env['sale.order'].create(dict of parameters)
sale_order.state = 'draft' # Set quotation state to draft
return {
'type': 'ir.actions.act_window',
'res_model': 'sale.order',
'view_mode': 'form',
'target': 'new',
'res_id': sale_order.id
}
By setting the state field of the sale_order record to 'draft', you ensure that the quotation is created in draft mode rather than being immediately confirmed with a number.
Hope this will help you
Thanks
Mehjabin Farsana & Savya Sachin thank you.
The sale.order is created if draft mode, however with a number. I think that it is due to the fact that I use ".create(dict)" and not ".new(dict)" function, but I don't know how to switch to new sale.order from stock.picking.
If I'm right, my problem can be summarized by : how to create a draft record with python self.env[model].new(dict) function and show it ?
I'm able to create a non draft (saved on database) ( with self.env[model].create(dict) ) record and show it. I'm also able to create an empty draft record, but not a draft record filled with my data.
Regards
Hi,
Try this,
class StockPicking(models.Model):
_inherit = 'stock.picking'
def convert_to_quotation(self):
sale_order = self.env['sale.order'].create({
'partner_id': self.partner_id.id, # Set the partner from the stock picking
'state': 'draft', # Set the state to draft
})
return {
'type': 'ir.actions.act_window',
'res_model': 'sale.order',
'view_mode': 'form',
'target': 'new',
'res_id': sale_order.id
}
Regards
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
Aanmelden
Odoo's flexibility allows a lot like delivery of products without restrictions, however, it could be nice a warning or button to propose/add for example a sales order
Ricardo Gross Thanks for your suggestion.
I have a button "Transfrm to Quotation" and, if we click on this button, it appears a confirm window to avoid mistake.