22
22
# You should have received a copy of the GNU Affero General Public License
23
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 _
24
##########################################################################
26
from openerp.osv import osv, fields
27
import openerp.tools as tools
28
from openerp.tools.translate import _
29
30
from tools import config
31
import openerp.netsvc as netsvc
31
32
import decimal_precision as dp
35
class picking_from_invoice(osv.osv_memory):
36
class picking_from_invoice(osv.TransientModel):
38
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"),
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):
44
def generate_picking(self, cr, uid, ids, context=None):
46
45
if context is None:
48
47
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)
48
company_id = self.pool.get('res.company')._company_default_get(
49
cr, uid, 'picking.from.invoice', context=context)
50
ware_ids = warehouse_obj.search(cr, uid, [(
51
'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]
53
raise osv.except_osv(_('Invalid action !'), _(
54
'You cannot create picking because you not have a warehouse!'))
55
ware_brw = ware_ids and warehouse_obj.browse(
56
cr, uid, ware_ids[0], context=context) or False
57
wzr_brw = self.browse(cr, uid, ids, context=context)[0]
55
58
for invoice in wzr_brw.invoice_ids:
56
59
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 \
60
if invoice.type in ('in_invoice', 'out_invoice'):
61
pick_name = self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.%s' % (invoice and
62
invoice.type == 'in_invoice' and
63
'in' or invoice.type == 'out_invoice' and
62
65
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 \
67
'origin': invoice.name,
69
invoice.type == 'in_invoice' and
70
'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,
73
'move_type': 'direct',
74
'address_id': invoice.partner_id and invoice.partner_id.address and invoice.partner_id.address[0].id,
75
'note': invoice.comment,
76
'invoice_state': 'invoiced',
77
'company_id': invoice.company_id.id,
76
79
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,
80
'name': line.name[:64],
81
'picking_id': picking_id,
82
'product_id': line.product_id.id,
83
'date': invoice.date_invoice,
84
'date_expected': invoice.date_invoice,
85
'product_uom': line.uos_id.id,
86
'product_qty': line.quantity,
87
'product_uos': line.uos_id and line.uos_id.id,
88
'address_id': invoice.partner_id and invoice.partner_id.address and invoice.partner_id.address[0].id,
89
'location_id': ware_brw and ware_brw.lot_stock_id and ware_brw.lot_stock_id.id,
90
'location_dest_id': ware_brw and ware_brw.lot_output_id and ware_brw.lot_output_id.id,
94
'company_id': invoice.company_id.id,
94
97
return {'type': 'ir.actions.act_window_close'}
96
picking_from_invoice()