Skip to Content
Menu
This question has been flagged

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
Discard
Author

How can i create it from  action_confirm method?

Best Answer

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
Discard
Author

How can i create it from action_confirm method?

Related Posts Replies Views Activity
2
Jul 23
1116
0
Dec 23
496
2
Apr 23
3035
2
Feb 23
3117
1
May 21
1974