Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
2246 Zobrazení

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
Zrušit
Autor

How can i create it from  action_confirm method?

Nejlepší odpověď

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
Zrušit
Autor

How can i create it from action_confirm method?

Related Posts Odpovědi Zobrazení Aktivita
2
čvc 23
2113
0
pro 23
1352
2
dub 23
5112
2
úno 23
3842
1
kvě 21
2934