~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to account_stock/wizard/wizard_stock_summary_product_vice.py

Added Modules : account_stock , purchase_number, sale_number

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
5
# WARNING: This program as such is intended to be used by professional
 
6
# programmers who take the whole responsability of assessing all potential
 
7
# consequences resulting from its eventual inadequacies and bugs
 
8
# End users who are looking for a ready-to-use solution with commercial
 
9
# garantees and support are strongly adviced to contract a Free Software
 
10
# Service Company
 
11
#
 
12
# This program is Free Software; you can redistribute it and/or
 
13
# modify it under the terms of the GNU General Public License
 
14
# as published by the Free Software Foundation; either version 2
 
15
# of the License, or (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 General Public License for more details.
 
21
#
 
22
# You should have received a copy of the GNU General Public License
 
23
# along with this program; if not, write to the Free Software
 
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
25
#
 
26
##############################################################################
 
27
 
 
28
import time
 
29
import wizard
 
30
import pooler
 
31
import mx.DateTime
 
32
 
 
33
dates_form = '''<?xml version="1.0"?>
 
34
<form string="Select period">
 
35
    <field name="company_id" colspan="4"/>
 
36
    <newline/>
 
37
    <field name="fiscalyear" colspan="4"/>
 
38
    <newline/>
 
39
    <field name="date1"/>
 
40
    <field name="date2"/>
 
41
    <newline/>
 
42
    <field name="method" colspan="4"/>
 
43
    <!--field name="mode" colspan="4"/-->
 
44
    <newline/>
 
45
    <field name="all" colspan="2"/>
 
46
    <separator string="Select Products" colspan="4"/>
 
47
    <newline/>
 
48
    <field name="products" colspan="4"/>
 
49
</form>'''
 
50
 
 
51
dates_fields = {
 
52
    'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
 
53
    'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
 
54
        'help': 'Keep empty for all open fiscal year'},
 
55
    'date1': {'string':'Start of Date', 'type':'date', 'required':True},
 
56
    'date2': {'string':'End of Date', 'type':'date', 'required':True},
 
57
    'products' : {
 
58
                  'string': 'Products', 
 
59
                  'type': 'many2many', 
 
60
                  'relation': 'product.product',
 
61
                  },
 
62
    'all':{'string':'All Products', 'type':'boolean'},
 
63
    'method': {'string': 'Method', 'type': 'selection','selection':[('fifo','FIFO'),('lifo','LIFO'),('weighted avg','WEIGHTED AVG'),('simple avg','SIMPLE AVG')]},
 
64
#    'mode': {'string': 'Mode', 'type': 'selection','selection':[('all invoice','All Invoice'),('with order','With Order'),('without order','WithOut Order')]},
 
65
}
 
66
 
 
67
class wizard_stock_summary_product_vice(wizard.interface):
 
68
    def _get_defaults(self, cr, uid, data, context):
 
69
        data['form']['method']='fifo'
 
70
        data['form']['mode']='all invoice'
 
71
        user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
 
72
        fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
 
73
        data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
 
74
        context['fiscalyear']= fiscalyear_obj.find(cr, uid)
 
75
        year_start_date = fiscalyear_obj.browse(cr, uid, context['fiscalyear'] ).date_start
 
76
        year_end_date = fiscalyear_obj.browse(cr, uid, context['fiscalyear'] ).date_stop 
 
77
        data['form']['date1'] =  mx.DateTime.strptime(year_start_date,"%Y-%m-%d").strftime("%Y-%m-%d")
 
78
        data['form']['date2'] =  mx.DateTime.strptime(year_end_date,"%Y-%m-%d").strftime("%Y-%m-%d")
 
79
        if user.company_id:
 
80
            company_id = user.company_id.id
 
81
        else:
 
82
            company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
 
83
        data['form']['company_id'] = company_id
 
84
 
 
85
        # to process company IDS
 
86
        user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
 
87
        company_ids = pooler.get_pool(cr.dbname).get('res.company')._get_company_children(cr, uid, user.company_id.id)
 
88
        dates_fields['company_id']['domain'] = "[('id','in',"+str(company_ids) +")]" 
 
89
 
 
90
        return data['form']
 
91
 
 
92
    states = {
 
93
        'init': {
 
94
            'actions': [_get_defaults],
 
95
            'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print') ]}
 
96
        },
 
97
        'report': {
 
98
            'actions': [],
 
99
            'result': {'type':'print', 'report':'stock.summary.prod.vice.report', 'state':'end'}
 
100
        }
 
101
    }
 
102
wizard_stock_summary_product_vice('stock.summary.prod.vice.report')
 
103