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

走远了吗. 提交于 2019-12-08 04:32:36

问题


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.


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/40215992/how-to-make-odoo-custom-stock-move-odoo-v8-and-v9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!