如何使 odoo 自定义股票移动(odoo v8 和 v9)

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

我正在创建自定义模块。有一个 one2many 字段。它有 -

quantity

unit of measure

source location

destination location

我需要将产品从源位置转移到目标位置。

在odoo v8中我看到了两个函数-

def do_detailed_transfer(self)

do_transfer()

但是 do_detailed_transfer 在 odoo v9 中不可用。

如何创建自定义库存移动,将两个版本的产品从源位置转移到目标位置?

谢谢。

我可以使用以下代码创建股票变动 -

        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

我正在测试您的代码,但出现错误“对象没有属性 'requisition_items',或 employee_id,产品 一定是我遗漏了一些重要的东西,你可以告诉我下一个是我的代码:

# -*- 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