我想在stockoo.picking.form中发送多个产品,在odoo10中形成mrp.bomline

时间:2017-06-30 07:26:36

标签: odoo-8 odoo odoo-10 odoo-9

  

Job Work Order where i want product from bom

我在采购订单上创建了一个按钮,用于打开stock.picking表单的材料,我想要多个产品。

def action_workorder_out(self):
    x = 0
    """ This opens the xml view specified in xml_id for the current Work Order in Manufacturing """
    self.ensure_one()
    xml_id = self.env.context.get('xml_id')
    if self.env.context.get('source_location_id'):

    defaults['location_id'] = self.env.context['source_location_id']
        # new_move = self.copy(defaults)
        res = self.env['ir.actions.act_window'].for_xml_id('stock', xml_id)

  purchase = self.env['purchase.order.line'].search([('order_id','=',self.product_id.id)])
        for record in purchase:
            x = record.product_id.id

        production = self.env['mrp.production'].search([('product_id','=',x)])

        for item in production:

            x = item.bom_id.id

        bomline = self.env['mrp.bom.line'].search([('bom_id','=',x)])


        for record in bomline:
         res.update(
                context={'default_states':'draft','default_origin':self.name,'default_partner_id': self.partner_id.id, 'default_incoterm_id': 0, 'default_picking_type_id':4    ,'default_move_lines': [(0,0, {'address_in_id':self.partner_id.id,'product_id':record.product_id.id,'product_uom': record.product_uom_id.id,'product_uom_qty':record.product_qty,'scrapped':False,'state':'draft','picking_id':False,'name': 'test','no_open': True,'no_create':True,'availability':1,'location_id':15,'location_dest_id':9,'picking_type_id':4,'date_expected':str(datetime.now()),})]}
            )
return res
return False

1 个答案:

答案 0 :(得分:1)

@api.multi
def stock_move_line(self,picking_id):
    # stock_pick = self.env['stock.picking'].browse(picking_id)
    stock_move = self.env['stock.move']
    purchase = self.env['purchase.order.line'].search([('order_id','=',self.product_id.id)])
    for record in purchase:
        x = record.product_id.id

    production = self.env['mrp.production'].search([('product_id','=',x)])

    for item in production:

        x = item.bom_id.id

    bomline = self.env['mrp.bom.line'].search([('bom_id','=',x)])


    for record in bomline:
        data = {

                'product_id':record.product_id.id,
                'product_uom':record.product_uom_id.id,
                'product_uom_qty':record.product_qty,
                'company_id': self.env.user.company_id.id,
                'name': self.name,
                'picking_id': picking_id,
                'address_in_id':self.partner_id.id, 
                'scrapped': False,
                'location_id':15,
                'location_dest_id':9,
                'picking_type_id':4,
                'procure_method':'make_to_stock',
                }

        move_line=stock_move.create(data)
这是针对BOM的材料
@api.multi
def action_workorder_out(self):
    x = 0
    update_qty = []
    res_obj = self.env['stock.picking']
    # """ This opens the xml view specified in xml_id for the current Work Order in Manufacturing """


    res=res_obj.create(
                {
                'work_center':self.work_center.id,
                'work_order':self.work_order ,
                'manfacturing_order':self.manfacturing_order.id,
                'origin':self.name,
                'partner_id': self.partner_id.id,
                'move_type':'direct',
                'company_id': self.env.user.company_id.id,
                'location_id':15,
                # 'default_location_id':15,
                'picking_type_id':4,
                'location_dest_id':9,   

                }
            )

    self.stock_move_line(res.id)

    if self.env.context.get('source_location_id'):

        defaults['location_id'] = self.env.context['source_location_id']

    action = self.env.ref('stock.action_picking_tree_all').read()[0]
    # res = self.env['ir.actions.act_window'].for_xml_id('stock', xml_id)
    action['views'] = [(self.env.ref('stock.view_picking_form').id, 'form')]
    action['res_id'] = res.id
    purchase_order = self.env['purchase.order.line'].search([])
    for rec in purchase_order:
        print rec.product_qty,"##############################"
        update_qty.append(rec.product_qty)
        update_qty[-1]
    return action
  

块引用   这是我们需要创建另一个函数并在库存,拣货和move_lines中创建数据。