【问题标题】:How to make odoo custom stock move (odoo v8 and v9)如何使 odoo 自定义库存移动(odoo v8 和 v9)
【发布时间】:2016-10-24 10:21:06
【问题描述】:

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

数量

计量单位

来源地点

目的地位置

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

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

def do_detailed_transfer(self)

和

do_transfer()

但是 do_detailed_transfer 在 odoo v9 中不可用。

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

谢谢。

【问题讨论】:

  • 你想通过代码转移股票?我认为 do_transfer 会起作用。
  • 是通过代码。我只想将产品从一个位置转移到另一个位置。我正在尝试使用 do_transfer 但没有实现。谢谢。
  • 您能告诉我到目前为止您为创建股票走势所做的工作吗?你遇到了什么问题。
  • 请看答案部分。
  • 嘿,我已经解决了这个问题。谢谢:)

标签: python-2.7 openerp odoo-8 odoo-9


【解决方案1】:

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

        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】:

我正在测试你的代码,我收到一个错误'对象没有属性'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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多