Skip to Content
Menu
This question has been flagged
925 Views

hello, I want to remove old product and create new one. However I carry on getting " You cannot validate a transfer if no quantities are reserved nor done. To force the transfer, switch in edit mode and encode the done quantities."  error once I call button_validate()
    def transfer_lot(self, lot, stock_picking,quantity):
        secondary_product_quant =
self.env['stock.quant'].search([

            ('product_id', '=', lot.product_id.id),

            ('location_id', '=', stock_picking.location_dest_id.id), 

            ('lot_id', '=', lot.id),        ], limit=1)

        if secondary_product_quant:

            secondary_product = self.env['product.product'].browse([lot.product_id.id])

            secondary_stock_quant = self.env['stock.quant'].search([

                    ('product_id', '=', secondary_product.id),

                    ('location_id', '=', stock_picking.location_dest_id.id),], limit=1)

            secondary_product_quant.update({

                'quantity': lot.product_qty            })

        else:

            secondary_product_quant = self.env['stock.quant'].create({

                'product_id': lot.product_id.id,

                'location_id': stock_picking.location_dest_id.id,

                'lot_id': lot.id,

                'quantity': quantity            })

        primary_stock_quant = self.env['stock.quant'].search([

            ('product_id', '=', stock_picking.product_id.id),

            ('location_id', '=', stock_picking.location_dest_id.id),

            ('lot_id', '=', stock_picking.lot_id.id),        ], limit=1)

        if primary_stock_quant:

            logging.info(f"Removing {primary_stock_quant}")

            logging.info(f"reached unlink 1, going to end transfer {primary_stock_quant.lot_id}

  {primary_stock_quant.product_id}  {primary_stock_quant.reserved_quantity}  {primary_stock_quant.available_quantity}   {primary_stock_quant.quantity}")            primary_stock_quant.sudo().unlink()

        self.create_end_transfer(lot=lot, quant_out=secondary_product_quant,quantity=quantity)

        defcreate_end_transfer(self, lot, quant_out,quantity):

        picking_type_split_end = self.env.ref("ecowood_splitting.operation_type_split_ending")

        lamels_unsorted = self.env.ref('ecowood_sorting.item_unsorted_lamels')

        order_lines = [(0, 0,

            {

                'product_id': lamels_unsorted.id

                'lot_id': lot.id,

                'product_uom': lamels_unsorted.uom_id.id,

                'company_id': self.env.user.company_id.id,

                'name': lamels_unsorted and lamels_unsorted.name orself.product_id.name,

                'location_id': picking_type_split_end.default_location_src_id.id,

                'location_dest_id': picking_type_split_end.default_location_dest_id.id,

                'product_uom_qty': quantity,            }            )]        logging.info(f"{order_lines}")

        picking_id = self.env['stock.picking'].create({

            'picking_type_id': picking_type_split_end.id,

            'location_id': picking_type_split_end.default_location_src_id.id,

            'location_dest_id': picking_type_split_end.default_location_dest_id.id,

            'move_lines': order_lines,

           'move_type': 'direct',            })

        picking_id.action_confirm()

        # Click 'Availability' button

        picking_id.action_assign()

        # Click 'Validate' button

        picking_id.button_validate()

Avatar
Discard