首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在产品- Odoo v9社区中,股票选择创建失败

在产品- Odoo v9社区中,股票选择创建失败
EN

Stack Overflow用户
提问于 2017-03-03 20:14:38
回答 1查看 448关注 0票数 0

我正在从stock.picking创建一个fleet.vehicle.log.services,如下所示:

代码语言:javascript
复制
@api.multi
def create_picking(self):
    self.ensure_one()
    vals = {
        'location_id': self.location_id.id,
        'location_dest_id': self.location_dest_id.id,
        'product_id': self.product_id.id,  # shouldn't be set on stock.picking, products are handled on it's positions (stock.move)
        'product_uom_qty': self.product_uom_qty,  # the same as for product_id
        'picking_type_id': self.picking_type_id.id
    }
    picking = self.env['stock.picking'].create(vals)
    return picking

创建拾取时,将使用视图上的一个按钮调用此方法,如下所示:

代码语言:javascript
复制
<button name="create_picking" string="Crear Picking" type="object" class="oe_highlight"/>

我的问题是,product_idproduct_uom_qty没有进入stock.picking,而是在stock.picking模型中使用One2many字段调用它们:

代码语言:javascript
复制
'move_lines': fields.one2many('stock.move', 'picking_id', string="Stock Moves", copy=True),

所以,product_idproduct_uom_qty都在stock.move上,所以当我点击按钮时,就会创建拣选,但是它不会占用产品,那么,我如何从函数中添加这种关系呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-05 20:36:09

创建挑选stock.move的行

然后更新move_lines中的stock.picking

代码语言:javascript
复制
@api.multi
def create_picking(self):
    self.ensure_one()
    #creating move_lines
    move_vals = {
        'product_id':your_product,
        'product_uom':your_uom,
        'product_uom_qty':product_uom_qty,
        'picking_type_id': self.picking_type_id.id,
        }
    move_ids = self.env['stock.move'].create(move_vals)
    vals = {
        'location_id': self.location_id.id,
        'location_dest_id': self.location_dest_id.id,
        'product_id': self.product_id.id,  # shouldn't be set on stock.picking, products are handled on it's positions (stock.move)
        'product_uom_qty': self.product_uom_qty,  # the same as for product_id
        'picking_type_id': self.picking_type_id.id
        #the move_lines here
        'move_lines':[(6,0,move_ids.ids)]
    }
    picking = self.env['stock.picking'].create(vals)
    return picking
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42587675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档