~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to ifrs_report/wizard/ifrs_report_wizard.py

  • Committer: Openerp User
  • Author(s): Vauxoo
  • Date: 2012-07-26 20:13:13 UTC
  • Revision ID: openerp@ingelub-erp-20120726201313-cgffyvd3zmqhn2w4

[FIX] bug a la hora de confirmar una orden de venta cuando el producto es de tipo servicio 
tomaba dicho porducto como si este fuera almacenable y tuviera stock cosa que no es asi 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    OpenERP, Open Source Management Solution
5
 
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6
 
#
7
 
#    This program is free software: you can redistribute it and/or modify
8
 
#    it under the terms of the GNU Affero General Public License as
9
 
#    published by the Free Software Foundation, either version 3 of the
10
 
#    License, or (at your option) any later version.
11
 
#
12
 
#    This program is distributed in the hope that it will be useful,
13
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
#    GNU Affero General Public License for more details.
16
 
#
17
 
#    You should have received a copy of the GNU Affero General Public License
18
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
#
20
 
##############################################################################
21
 
 
22
 
import time
23
 
 
24
 
from osv import fields, osv
25
 
from tools.translate import _
26
 
import netsvc
27
 
 
28
 
 
29
 
class ifrs_report_wizard(osv.osv_memory):
30
 
 
31
 
    """ Wizard que permite al usuario elegir que periodo quiere imprimir del año fiscal """
32
 
 
33
 
    _name = 'ifrs.report.wizard'
34
 
    _description = 'IFRS Report'
35
 
 
36
 
    def onchange_company_id(self, cr, uid, ids, company_id, context=None):
37
 
        context = context or {}
38
 
        context['company_id'] = company_id
39
 
        res = {'value': {}}
40
 
 
41
 
        if not company_id:
42
 
            return res
43
 
 
44
 
        cur_id = self.pool.get('res.company').browse(
45
 
            cr, uid, company_id, context=context).currency_id.id
46
 
        fy_id = self.pool.get('account.fiscalyear').find(
47
 
            cr, uid, context=context)
48
 
 
49
 
        res['value'].update({'fiscalyear_id': fy_id})
50
 
        res['value'].update({'currency_id': cur_id})
51
 
        return res
52
 
 
53
 
    _columns = {
54
 
        'period': fields.many2one('account.period', 'Force period', help='Fiscal period to assign to the invoice. Keep empty to use the period of the current date.'),
55
 
        'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', help='Fiscal Year'),
56
 
        'company_id': fields.many2one('res.company', string='Company', ondelete='cascade', required=True, help='Company name'),
57
 
        'currency_id': fields.many2one('res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"),
58
 
        'exchange_date': fields.date('Exchange Date', help='Date of change that will be printed in the report, with respect to the currency of the company'),
59
 
        'report_type': fields.selection([
60
 
            ('all', 'All Fiscalyear'),
61
 
            ('per', 'Force Period')],
62
 
            string='Type', required=True, help='Indicates if the report it will be printed for the entire fiscal year, or for a particular period'),
63
 
        'columns': fields.selection([
64
 
            ('ifrs', 'Two Columns'),
65
 
            ('webkitaccount.ifrs_12', 'Twelve Columns'),
66
 
            #('ifrs_12_partner_detail', 'With Partner Detail')
67
 
        ],
68
 
            string='Number of Columns',
69
 
            help='Number of columns that will be printed in the report:'
70
 
            " -Two Colums(02),-Twelve Columns(12)"),
71
 
        'target_move': fields.selection([('posted', 'All Posted Entries'),
72
 
                                        ('all', 'All Entries'),
73
 
                                         ], 'Target Moves', help='Print All Accounting Entries or just Posted Accounting Entries'),
74
 
    }
75
 
 
76
 
    _defaults = {
77
 
        'report_type': 'all',
78
 
        'target_move': 'all',
79
 
        'company_id': lambda self, cr, uid, c: self.pool.get('ifrs.ifrs').browse(cr, uid, c.get('active_id')).company_id.id,
80
 
        'fiscalyear_id': lambda self, cr, uid, c: self.pool.get('ifrs.ifrs').browse(cr, uid, c.get('active_id')).fiscalyear_id.id,
81
 
        'exchange_date': fields.date.today,
82
 
        'columns': 'ifrs'
83
 
    }
84
 
 
85
 
    def default_get(self, cr, uid, fields, context=None):
86
 
        if context is None:
87
 
            context = {}
88
 
        res = super(ifrs_report_wizard, self).default_get(
89
 
            cr, uid, fields, context=context)
90
 
        # res.update({'uid_country':
91
 
        # self._get_country_code(cr,uid,context=context)})
92
 
        return res
93
 
 
94
 
    def _get_period(self, cr, uid, context={}):
95
 
 
96
 
        """ Return the current period id """
97
 
 
98
 
        account_period_obj = self.pool.get('account.period')
99
 
        ids = account_period_obj.find(
100
 
            cr, uid, time.strftime('%Y-%m-%d'), context=context)
101
 
        period_id = ids[0]
102
 
        return period_id
103
 
 
104
 
    def _get_fiscalyear(self, cr, uid, context={}, period_id=False):
105
 
 
106
 
        """ Return fiscalyear id for the period_id given.
107
 
            If period_id is nor given then return the current fiscalyear """
108
 
 
109
 
        if period_id:
110
 
            period_obj = self.pool.get(
111
 
                'account.period').browse(cr, uid, period_id)
112
 
            fiscalyear_id = period_obj.fiscalyear_id.id
113
 
        else:
114
 
            fiscalyear_obj = self.pool.get('account.fiscalyear')
115
 
            ids = fiscalyear_obj.find(cr, uid, time.strftime(
116
 
                '%Y-%m-%d'), context=context)
117
 
            fiscalyear_id = ids
118
 
        return fiscalyear_id
119
 
 
120
 
    def print_report(self, cr, uid, ids, context={}):
121
 
        datas = {'ids': context.get('active_ids', [])}
122
 
        wizard_ifrs = self.browse(cr, uid, ids, context=context)[0]
123
 
        datas['report_type'] = str(wizard_ifrs.report_type)
124
 
        datas['company'] = wizard_ifrs.company_id.id
125
 
        datas['columns'] = str(wizard_ifrs.columns)
126
 
        datas['target_move'] = wizard_ifrs.target_move
127
 
        datas['exchange_date'] = wizard_ifrs.exchange_date
128
 
        datas['currency_wizard'] = wizard_ifrs.currency_id.id
129
 
        datas['currency_wizard_name'] = wizard_ifrs.currency_id.name
130
 
 
131
 
        if datas['report_type'] == 'all':
132
 
            datas['fiscalyear'] = wizard_ifrs.fiscalyear_id.id or self._get_fiscalyear(
133
 
                cr, uid, context=context)
134
 
            datas['period'] = False
135
 
        else:
136
 
            datas['columns'] = 'ifrs'
137
 
            datas['period'] = wizard_ifrs.period.id or self._get_period(
138
 
                cr, uid, context=context)
139
 
            datas['fiscalyear'] = self._get_fiscalyear(
140
 
                cr, uid, context=context, period_id=datas['period'])
141
 
 
142
 
        return {
143
 
            'type': 'ir.actions.report.xml',
144
 
            'report_name': datas['columns'],
145
 
            'datas': datas
146
 
        }
147
 
 
148
 
ifrs_report_wizard()
149
 
 
150
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: