Ir al contenido
Menú
Se marcó esta pregunta

I'm trying to create dellivery orders based on warehouses selected 
i created a function on sale order to create multi delivery orders , but delivery orders not found
This is the code:

import random
from odoo import models , fields,api,_
class SaleOrder(models.Model):
_name='sale.order'
_inherit = 'sale.order'
warehouse_ids = fields.Many2many('stock.warehouse', string='Warehouses')

@api.model
def create(self, vals):
res = super(SaleOrder, self).create(vals)
for line in res.order_line.warehouse_ids:

for w in line:
picking_vals = {
'partner_id': res.partner_shipping_id.id,
'location_id': w.lot_stock_id.id,
'location_dest_id': res.partner_shipping_id.property_stock_customer.id,
'picking_type_id':random.randint(1,6),
}
self.env['stock.picking'].create(picking_vals)
print(picking_vals)
return res
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

warehouse_ids = fields.Many2many('stock.warehouse',string="Warehouses ")

class ProductTemplate(models.Model):
_inherit = 'product.template'
warehouse_id = fields.Many2one('stock.warehouse',string="Warehouse ")


class ProductProduct(models.Model):
_inherit = 'product.product'
warehouse_id = fields.Many2one('stock.warehouse',string="Warehouse ")



it is not exist:

only one delivery and i select two warehouses:

Avatar
Descartar
Autor

How can i create it from  action_confirm method?

Mejor respuesta

Hi,

Seems there is issue with the logic you have added, actually you have to generate the pickings/delivery orders, when you confirm the sale order, you have to inherit the action_confirm method(or any other method) and add your necessary logic.


If you try to achieve it from the create method, irrespective of whether the order is confirmed, system will try to create DO.


Also in order to show the created DO in the smart button, which is currently controlled by the picking_ids one2many field in sale order, when you create new picking based on your logic, you have to set the value of sale_id field in the picking as current sale order id.


picking_vals = {
'partner_id': res.partner_shipping_id.id,
'location_id': w.lot_stock_id.id,
'sale_id': res.id,
'location_dest_id': res.partner_shipping_id.property_stock_customer.id,
'picking_type_id': random.randint(1, 6),
}



Thanks & Regards

Walnut Software Solutions

Avatar
Descartar
Autor

How can i create it from action_confirm method?

Publicaciones relacionadas Respuestas Vistas Actividad
2
jul 23
2051
0
dic 23
1260
2
abr 23
4991
2
feb 23
3775
1
may 21
2868