How to create a shipment (in) with incoming_moves (lines)

Best regard,

I have been using 2 different methods to create a shipment (in) with their respective lines (incoming_moves) as shown below:

    @classmethod
    def _create_shipment(cls, data):
        if not data:
            return
        pool = Pool()
        Move = pool.get('stock.move')
        Shipment = pool.get('stock.shipment.in')
        # Se procede a crear los envíos segun la compra
        # to_save = []
        to_create = []
        for number in data:
            purchase  = data[number]['purchase']
            if purchase.shipments:
                continue
            # line_moves = {}
            # for line in purchase.lines:
            #     if line.moves and line.product not in line_moves:
            #         for m in line.moves:
            #             if not m.shipment:
            #                 line_moves[line.product] = m
            # Se crea el envío
            # shipment = Shipment(
            #     warehouse=purchase.warehouse.id,
            #     supplier=purchase.party.id,
            #     company=purchase.company.id,
            #     effective_date=data[number]['date'],
            #     planned_date=data[number]['date'],
            #     )
            shipment = {
                'reference': purchase.reference,
                'warehouse': purchase.warehouse.id,
                'supplier': purchase.party.id,
                'company': purchase.company.id,
                'effective_date': data[number]['date'],
                'planned_date': data[number]['date'],
            }
            purchase_lines = list(purchase.lines)
            moves = []
            for dict in data[number]['lines']:
                move = {
                    'from_location': dict['from_location'].id,
                    'to_location': dict['to_location'].id,
                    'product': dict['product'].id,
                    'uom': dict['uom'].id,
                    'quantity': dict['quantity'],
                    'unit_price': dict['unit_price'],
                    'currency': purchase.company.currency.id,
                }
            #     if dict['product'] in line_moves:
            #         move = line_moves[dict['product']]
            #         move.quantity = dict['quantity']
            #         move.unit_price = dict['unit_price']
            #     else:
            #         move = Move()
            #         move.from_location = dict['from_location']
            #         move.to_location = dict['to_location']
            #         move.product = dict['product']
            #         move.uom = dict['uom']
            #         move.quantity = dict['quantity']
            #         move.unit_price = dict['unit_price']
            #         move.currency = purchase.company.currency
                if purchase_lines:
                    # move.origin = str(purchase_lines.pop())
                    move['origin'] = str(purchase_lines.pop())
                print(move)
                moves.append(move)
            #--------------------------------REVISAR ERROR--------------------------------#
            if moves:
                # shipment.moves = (list(getattr(shipment, 'moves', [])) + moves)
                shipment['incoming_moves'] = [('create', moves)]
            # shipment.reference = purchase.reference
            # to_save.append(shipment)
            to_create.append(shipment)

        # Shipment.save(to_save)
        to_save = Shipment.create(to_create)
        Shipment.receive(to_save)
        Shipment.done(to_save)

But when I run the code, I see from the Tryton client that the submission is left without the lines, as I show in the following screenshots:


But the movements are created and I can see them from the tree view of stock.move:

I thank the people who can guide me to give a solution.

I guess you miss to add the shipment reference to the moves.

As can be seen in the following screenshot, the field contains the shipping reference:

I guess the locations of the moves are not correct to be incoming moves.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.