Search code examples
python-2.7odooodoo-8odoo-9

How to make odoo custom stock move (odoo v8 and v9)


I am creating a custom module. There is an one2many field. It has -

quantity

unit of measure

source location

destination location

I need to transfer the product from source location to destination location.

In odoo v8 I saw two functions -

def do_detailed_transfer(self)

and

do_transfer()

But do_detailed_transfer is not available in odoo v9.

How can I create a custom stock move which will transfer products from source location to destination location for both versions?

Thanks.


Solution

  • I am able to create stock move with following code -

            res = {}
            Move = self.env['stock.move']
            for transfer in self:
                moves = self.env['stock.move']
                for products in transfer.requisition_items:
                    move = Move.create({
                        'name': transfer.employee_id.name,
                        'product_id': products.product_id.id,
                        'restrict_lot_id': False,
                        'product_uom_qty': products.delivery_quantity,
                        'product_uom': 1, #TODO: Change the test value 1 to produc_uom
                        'partner_id': 1, #TODO: Change the test value 1 to partner_id
                        'location_id': products.source_location.id,
                        'location_dest_id': products.destination_location.id,
                    })
                    moves |= move
                    moves.action_done()
                    products.write({'move_id': move.id, 'state': 'done'})
    
                res[transfer.id] = move.id
            return res