Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
1901 มุมมอง

I did this function to create delivery order for each order line when the locations is different in order lines

and create one deivery order when all order lines have the same location

but only one product appear in the delivery order when i select multi product with the same location

class SaleOrder(models.Model):
_inherit = 'sale.order'

@api.model
def action_confirm(self):
res = super(SaleOrder, self)

locations = []
for line in res.order_line:

if line.location_ids not in locations:
locations.append(line.location_ids)
picking_vals = {
'origin':res.name,
'partner_id': res.partner_shipping_id.id,
'location_id': line.location_ids.id,
'location_dest_id': res.partner_shipping_id.property_stock_customer.id,
'picking_type_id': self.env.ref('stock.picking_type_out').id,
'sale_id': res.id,

'move_ids_without_package': [( {
'name': line.name,
'product_id': line.product_id.id,
'product_uom': line.product_template_id.uom_id.id,
'location_id': line.location_ids.id,
'location_dest_id': res.partner_shipping_id.property_stock_customer.id,
'product_uom_qty':line.product_uom_qty,
#'quantity_done': ,
#'forecast_availability':
})],
}

delivery_order=self.env['stock.picking'].create(picking_vals)
delivery_order.state= 'assigned'
#res.write({'state':'done'})
res.write(res._prepare_confirmation_values())
return res


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

The problem lies in the fact that you are appending unique places by using the locations list to keep track of them. To make a delivery order for each set of order lines with the same location, you should first arrange the order lines according to location.

class SaleOrder(models.Model):
_inherit = 'sale.order'

@api.model
def action_confirm(self):
    res = super(SaleOrder, self)

    locations = {}
    for line in res.order_line:
        location_id = line.location_ids.id

        if location_id not in locations:
            locations[location_id] = []

        locations[location_id].append(line)

    for location_id, order_lines in locations.items():
        picking_vals = {
            'origin': res.name,
            'partner_id': res.partner_shipping_id.id,
            'location_id': location_id,
            'location_dest_id': res.partner_shipping_id.property_stock_customer.id,
            'picking_type_id': self.env.ref('stock.picking_type_out').id,
            'sale_id': res.id,
            'move_ids_without_package': [],
        }

        for line in order_lines:
            move_vals = {
                'name': line.name,
                'product_id': line.product_id.id,
                'product_uom': line.product_template_id.uom_id.id,
                'location_id': location_id,
                'location_dest_id': res.partner_shipping_id.property_stock_customer.id,
                'product_uom_qty': line.product_uom_qty,
            }
            picking_vals['move_ids_without_package'].append((0, 0, move_vals))

        delivery_order = self.env['stock.picking'].create(picking_vals)
        delivery_order.state = 'assigned'

    res.write(res._prepare_confirmation_values())
    return res


Hope it helps

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
พ.ย. 23
3891
2
พ.ค. 25
2870
0
พ.ย. 24
559
1
ส.ค. 24
989
1
ส.ค. 24
2032