~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: Nhomar Hernandez
  • Date: 2013-04-19 20:33:12 UTC
  • mfrom: (542.1.314 addons-vauxoo)
  • Revision ID: nhomar@gmail.com-20130419203312-o35v7dn79l6vur0t
[MERGE - PEP8 AND V7-MIG] All migrated to V7 Just
improved osv.osv => osv.Model, osv.osv_memory => osv.TransientModel
import inside openerp.* enviroment
Erased class instansiation no necesarry anymore in V7
AUTOPEP8 run, Left PEP8 long lines manually.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#    Module Writen to OpenERP, Open Source Management Solution
5
5
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
6
6
#    All Rights Reserved
7
 
###############Credits######################################################
8
 
#    Coded by: Vauxoo C.A.           
 
7
# Credits######################################################
 
8
#    Coded by: Vauxoo C.A.
9
9
#    Planified by: Nhomar Hernandez
10
10
#    Audited by: Vauxoo C.A.
11
11
#############################################################################
21
21
#
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
 
################################################################################
25
 
 
26
 
from osv import fields, osv
27
 
import tools
28
 
from tools.translate import _
 
24
##########################################################################
 
25
 
 
26
from openerp.osv import osv, fields
 
27
import openerp.tools as tools
 
28
from openerp.tools.translate import _
 
29
 
29
30
from tools import config
30
 
import netsvc
 
31
import openerp.netsvc as netsvc
31
32
import decimal_precision as dp
32
33
import time
33
34
 
34
35
 
35
 
class picking_from_invoice(osv.osv_memory):
 
36
class picking_from_invoice(osv.TransientModel):
36
37
 
37
 
    
38
38
    _name = 'picking.from.invoice'
39
39
    _columns = {
40
 
        'invoice_ids':fields.many2many('account.invoice','invoice_rel','invoice1','invoice2','Invoices',help="Select the invoices to account move cancel"),
41
 
        
 
40
        'invoice_ids': fields.many2many('account.invoice', 'invoice_rel', 'invoice1', 'invoice2', 'Invoices', help="Select the invoices to account move cancel"),
 
41
 
42
42
    }
43
 
    
44
 
    
45
 
    def generate_picking(self,cr,uid,ids,context=None):
 
43
 
 
44
    def generate_picking(self, cr, uid, ids, context=None):
46
45
        if context is None:
47
46
            context = {}
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)
51
52
        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]
 
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
61
64
                                                                          'out'))
62
65
                    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 \
 
66
                        'name': pick_name,
 
67
                        'origin': invoice.name,
 
68
                        'type': invoice and
 
69
                        invoice.type == 'in_invoice' and
 
70
                                        'in' or invoice.type == 'out_invoice' and
68
71
                                        '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
 
                            })
 
72
                        'state': 'auto',
 
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,
 
78
                    })
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,
88
 
                            'tracking_id': False,
89
 
                            'state': 'draft',
90
 
                            'note': line.note,
91
 
                            'company_id': invoice.company_id.id,
92
 
                        })
93
 
                
 
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,
 
91
                        'tracking_id': False,
 
92
                        'state': 'draft',
 
93
                        'note': line.note,
 
94
                        'company_id': invoice.company_id.id,
 
95
                    })
 
96
 
94
97
        return {'type': 'ir.actions.act_window_close'}
95
 
    
96
 
picking_from_invoice()
97