2016-06-22 4 views
1

Ich möchte einen Auftrag picking_out der Rechnung machen in der OpenERP ich diese https://www.odoo.com/apps/modules/7.0/picking_from_invoice/ gefundenGenerieren von Rechnungen Kommissionierung OpenERP

Aber sie haben jedes Element in einem Lieferauftrag erstellen Gibt es eine Lösung seiner eigenen

der Code dies für fonction

class picking_from_invoice(osv.TransientModel): 

_name = 'picking.from.invoice' 
_columns = { 
    'invoice_ids': fields.many2many('account.invoice', 'invoice_rel', 
     'invoice1', 'invoice2', 'Invoices', 
     help="Select the invoices to account move cancel"), 

} 

def generate_picking(self, cr, uid, ids, context=None): 
    if context is None: 
     context = {} 
    warehouse_obj = self.pool.get('stock.warehouse') 
    company_id = self.pool.get('res.company')._company_default_get(
     cr, uid, 'picking.from.invoice', context=context) 
    ware_ids = warehouse_obj.search(cr, uid, [(
     'company_id', '=', company_id)], context=context) 
    if not ware_ids: 
     raise osv.except_osv(_('Invalid action !'), _(
      'You cannot create picking because you not\ 
      have a warehouse!')) 
    ware_brw = ware_ids and warehouse_obj.browse(
     cr, uid, ware_ids[0], context=context) or False 
    wzr_brw = self.browse(cr, uid, ids, context=context)[0] 
    for invoice in wzr_brw.invoice_ids: 
     for line in invoice.invoice_line: 
      if invoice.type in ('in_invoice', 'out_invoice'): 
       pick_name = self.pool.get('ir.sequence').get(cr, 
          uid, 'stock.picking.%s' % (invoice and 
            invoice.type == 'in_invoice' and 
            'in' or invoice.type == 'out_invoice' and 
            'out')) 
       picking_id = self.pool.get('stock.picking').create(cr, uid, { 
        'name': pick_name, 
        'origin': invoice.name, 
        'type': invoice and 
        invoice.type == 'in_invoice' and 
            'in' or invoice.type == 'out_invoice' 
            and 'out', 
        'state': 'auto', 
        'move_type': 'direct', 
        'note': invoice.comment, 
        'invoice_state': 'invoiced', 
        'company_id': invoice.company_id.id, 
       }) 
       move_id = self.pool.get('stock.move').create(cr, uid, { 
        'name': line.name[:64], 
        'picking_id': picking_id, 
        'product_id': line.product_id.id, 
        'date': invoice.date_invoice, 
        'date_expected': invoice.date_invoice, 
        'product_uom': line.uos_id.id, 
        'product_qty': line.quantity, 
        'product_uos': line.uos_id and line.uos_id.id, 
        'address_id': invoice.partner_id and 
        invoice.partner_id.street and 
        invoice.partner_id.street[0].id, 
        'location_id': ware_brw and ware_brw.lot_stock_id and 
        ware_brw.lot_stock_id.id, 
        'location_dest_id': ware_brw and 
        ware_brw.lot_output_id and 
        ware_brw.lot_output_id.id, 
        'tracking_id': False, 
        'state': 'draft', 
        'note': invoice.comment, 
        'partner_id': invoice.partner_id.id, 
        'company_id': invoice.company_id.id, 
       }) 

    return {'type': 'ir.actions.act_window_close'} 

Antwort

1

später laufen Eigentlich müssen Sie nur die for-Schleife für die Rechnungszeilen lassen, wie:

for invoice in wzr_brw.invoice_ids: 
    if invoice.type in ('in_invoice', 'out_invoice'): 
     # name... 
     picking_id = self.pool.get('stock.picking').create(cr, uid, {#... 
     }) 
     for line in invoice.invoice_line: 
      move_id = self.pool.get('stock.move').create(cr, uid, {#... 
      }) 
+0

denke, du gute Lösung – developper