从发票openerp生成拣配

时间:2016-06-22 13:18:53

标签: python openerp

我想在openerp中订购invoice_out发票 我找到了这个https://www.odoo.com/apps/modules/7.0/picking_from_invoice/

但他们确实在交货单中创建了每件商品 是否有他自己的解决方案

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

1 个答案:

答案 0 :(得分:1)

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

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, {#...
            })