تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2281 أدوات العرض

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:

الصورة الرمزية
إهمال
الكاتب

How can i create it from  action_confirm method?

أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب

How can i create it from action_confirm method?

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
يوليو 23
2141
0
ديسمبر 23
1385
Delivery order sale تم الحل
2
أبريل 23
5187
2
فبراير 23
3864
1
مايو 21
2961