1
votes

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.

2
You want to transfer stock through code ? do_transfer will work I think.Emipro Technologies Pvt. Ltd.
yes through code. I want to just transfer products from one location to another. I am trying to use do_transfer but not achieving it. Thanks.Tanzil Khan
Can you show me what you have done so far in order to create stock move ? and what's the problem you faced.Emipro Technologies Pvt. Ltd.
Please see in the answer section.Tanzil Khan
hei, I have solved the issue. Thanks :)Tanzil Khan

2 Answers

2
votes

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
0
votes

I'm testing your code and I got an error ' object has no attribute 'requisition_items', or employee_id, products It must be that I'm missing something that matters, you could tell me it's my code next:

# -*- coding: utf-8 -*-

from openerp import models, fields, api

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

articulo =  fields.Many2one('product.product', 'Articulo')
cantidad1 =  fields.Integer('Cantidad',default=0)

@api.onchange('envases1')
def new_move_stock(self):
    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