2
# -*- encoding: utf-8 -*-
3
###########################################################################
4
# Module Writen to OpenERP, Open Source Management Solution
5
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
7
###############Credits######################################################
8
# Coded by: Vauxoo C.A.
9
# Planified by: Nhomar Hernandez
10
# Audited by: Vauxoo C.A.
11
#############################################################################
12
# This program is free software: you can redistribute it and/or modify
13
# it under the terms of the GNU Affero General Public License as published by
14
# the Free Software Foundation, either version 3 of the License, or
15
# (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU Affero General Public License for more details.
22
# You should have received a copy of the GNU Affero General Public License
23
# along with this program. If not, see <http://www.gnu.org/licenses/>.
24
################################################################################
26
from osv import fields, osv
28
from tools.translate import _
29
from tools import config
31
import decimal_precision as dp
35
class picking_from_invoice(osv.osv_memory):
38
_name = 'picking.from.invoice'
40
'invoice_ids':fields.many2many('account.invoice','invoice_rel','invoice1','invoice2','Invoices',help="Select the invoices to account move cancel"),
45
def generate_picking(self,cr,uid,ids,context=None):
48
warehouse_obj = self.pool.get('stock.warehouse')
49
company_id = self.pool.get('res.company')._company_default_get(cr, uid, 'picking.from.invoice', context=context)
50
ware_ids = warehouse_obj.search(cr,uid,[('company_id','=',company_id)],context=context)
52
raise osv.except_osv(_('Invalid action !'), _('You cannot create picking because you not have a warehouse!'))
53
ware_brw = ware_ids and warehouse_obj.browse(cr,uid,ware_ids[0],context=context) or False
54
wzr_brw = self.browse(cr,uid,ids,context=context)[0]
55
for invoice in wzr_brw.invoice_ids:
56
for line in invoice.invoice_line:
57
if invoice.type in ('in_invoice','out_invoice'):
58
pick_name = self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.%s'%( invoice and \
59
invoice.type == 'in_invoice' and \
60
'in' or invoice.type == 'out_invoice' and \
62
picking_id = self.pool.get('stock.picking').create(cr, uid, {
64
'origin': invoice.name,
66
invoice.type == 'in_invoice' and \
67
'in' or invoice.type == 'out_invoice' and \
70
'move_type': 'direct',
71
'address_id': invoice.partner_id and invoice.partner_id.address and invoice.partner_id.address[0].id,
72
'note': invoice.comment,
73
'invoice_state': 'invoiced',
74
'company_id': invoice.company_id.id,
76
move_id = self.pool.get('stock.move').create(cr, uid, {
77
'name': line.name[:64],
78
'picking_id': picking_id,
79
'product_id': line.product_id.id,
80
'date': invoice.date_invoice,
81
'date_expected': invoice.date_invoice,
82
'product_uom': line.uos_id.id,
83
'product_qty': line.quantity,
84
'product_uos': line.uos_id and line.uos_id.id,
85
'address_id': invoice.partner_id and invoice.partner_id.address and invoice.partner_id.address[0].id,
86
'location_id': ware_brw and ware_brw.lot_stock_id and ware_brw.lot_stock_id.id,
87
'location_dest_id': ware_brw and ware_brw.lot_output_id and ware_brw.lot_output_id.id,
91
'company_id': invoice.company_id.id,
94
return {'type': 'ir.actions.act_window_close'}
96
picking_from_invoice()