Python 从发票openerp生成领料

Python 从发票openerp生成领料,python,openerp,Python,Openerp,我想订一张开封单,从发票中提货 我找到了这个 但他们确实创建了交货单中的每一项 有他自己的解决办法吗 这是fonction的代码 class picking_from_invoice(osv.TransientModel): _name = 'picking.from.invoice' _columns = { 'invoice_ids': fields.many2many('account.invoice', 'invoice_rel', 'invoice1', 'i

我想订一张开封单,从发票中提货 我找到了这个

但他们确实创建了交货单中的每一项 有他自己的解决办法吗

这是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'}

实际上,您只需要让发票行的for循环稍后运行,如:

wzr_brw.invoice_id中发票的
:
如果invoice.in('in_invoice'、'out_invoice'):
#名字。。。
picking_id=self.pool.get('stock.picking').create(cr,uid,{#。。。
})
对于发票中的行。发票\行:
move_id=self.pool.get('stock.move').create(cr,uid,{#。。。
})