在拣货移动线中添加行

时间:2018-07-02 09:47:59

标签: odoo odoo-8 odoo-10

在我的方法中,我从stock.pickings中删除行,并希望从模型中添加其他行。但出现错误AttributeError:'stock.move'对象没有属性'get'

@api.multi
        def _action_procurement_create(self):
            res = super(SaleOrderLine, self)._action_procurement_create()
            order_line_bom = self.env['sale.order.line.bom'].search([('sale_order_line_id', '=', self.id )])
            stock_move_lines = self.env['stock.move']
            created_stock_move_lines = self.env['stock.move']
            vals = {}
            for order in self.order_id:
                if self.product_id.bom_ids:
                    order.picking_ids.move_lines.state = 'draft'
                    for move_line in order.picking_ids.move_lines:
                        move_line.unlink()
                    for bom_line in order_line_bom:
                        vals['product_id'] = bom_line.product_id.id,
                        vals['product_uom'] = 1,
                        vals['location_id'] = 1,
                        vals['name'] = bom_line.product_id.name,
                        vals['location_dest_id'] = 1,
                        created_stock_move_lines  += stock_move_lines.create(vals)
                    order.create(stock_move_lines)

2 个答案:

答案 0 :(得分:1)

您已定义:

stock_move_lines = self.env['stock.move']

然后尝试将其传递给创建方法:

order.create(stock_move_lines)

model.py

中所述
:param dict vals:
        values for the model's fields, as a dictionary::

            {'field_name': field_value, ...}

        see :meth:`~.write` for details

答案 1 :(得分:1)

请尝试对您有所帮助:

@api.multi
def _action_procurement_create(self):
    res = super(SaleOrderLine, self)._action_procurement_create()
    order_line_bom = self.env['sale.order.line.bom'].search([('sale_order_line_id', '=', self.id )])
    stock_move_lines = self.env['stock.move']
    created_stock_move_lines = self.env['stock.move']
    vals = {}
    for order in self.order_id:
        if self.product_id.bom_ids:
            order.picking_ids.move_lines.state = 'draft'
            for move_line in order.picking_ids.move_lines:
                move_line.unlink()
                for bom_line in order_line_bom:
                    vals = {
                        'product_id': bom_line.product_id.id,
                        'product_uom': 1,
                        'location_id': 1,
                        'name': bom_line.product_id.name,
                        'location_dest_id': 1,
                         }
                    created_stock_move_lines  += stock_move_lines.create(vals)
                order.create(stock_move_lines)