~vauxoo/addons-vauxoo/8.0-import_tax_tariff-dev-yani-rev-2

« back to all changes in this revision

Viewing changes to picking_from_invoice/wizard/picking_from_invoice.py

  • Committer: Jose Antonio
  • Date: 2012-05-13 03:02:20 UTC
  • mto: This revision was merged to the branch mainline in revision 251.
  • Revision ID: jose@vauxoo.com-20120513030220-xl0cxvnkt0ifs070

[ADD] Added new module to generate picking from a invoice previous create

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- encoding: utf-8 -*-
 
3
###########################################################################
 
4
#    Module Writen to OpenERP, Open Source Management Solution
 
5
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
 
6
#    All Rights Reserved
 
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.
 
16
#
 
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.
 
21
#
 
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
################################################################################
 
25
 
 
26
from osv import fields, osv
 
27
import tools
 
28
from tools.translate import _
 
29
from tools import config
 
30
import netsvc
 
31
import decimal_precision as dp
 
32
import time
 
33
 
 
34
 
 
35
class picking_from_invoice(osv.osv_memory):
 
36
 
 
37
    
 
38
    _name = 'picking.from.invoice'
 
39
    _columns = {
 
40
        'invoice_ids':fields.many2many('account.invoice','invoice_rel','invoice1','invoice2','Invoices',help="Select the invoices to account move cancel"),
 
41
        
 
42
    }
 
43
    
 
44
    
 
45
    def generate_picking(self,cr,uid,ids,context=None):
 
46
        if context is None:
 
47
            context = {}
 
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)
 
51
        if not ware_ids:
 
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 \
 
61
                                                                          'out'))
 
62
                    picking_id = self.pool.get('stock.picking').create(cr, uid, {
 
63
                                'name': pick_name,
 
64
                                'origin': invoice.name,
 
65
                                'type': invoice and \
 
66
                                        invoice.type == 'in_invoice' and \
 
67
                                        'in' or invoice.type == 'out_invoice' and \
 
68
                                        'out',
 
69
                                'state': 'auto',
 
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,
 
75
                            })
 
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,
 
88
                            'tracking_id': False,
 
89
                            'state': 'draft',
 
90
                            'note': line.note,
 
91
                            'company_id': invoice.company_id.id,
 
92
                        })
 
93
                
 
94
        return {'type': 'ir.actions.act_window_close'}
 
95
    
 
96
picking_from_invoice()
 
97