Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
1732 Vistas

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

Avatar
Descartar

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

Autor

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.

Mejor respuesta

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

Avatar
Descartar
Autor Mejor respuesta

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

Avatar
Descartar
Mejor respuesta

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

Avatar
Descartar