~openbias/bias-trunk/bias-public-trunk

« back to all changes in this revision

Viewing changes to l10n_mx/wizard/account_vat_declaration.py

  • Committer: Jose Patricio
  • Date: 2011-10-19 03:16:40 UTC
  • Revision ID: josepato@bias.com.mx-20111019031640-05zd7r5lxwx084qu
el push inicial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution   
 
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
import wizard
 
23
import time
 
24
import datetime
 
25
import pooler
 
26
import base64
 
27
 
 
28
from tools.translate import _
 
29
 
 
30
form_fyear = """<?xml version="1.0"?>
 
31
<form string="Select Period">
 
32
    <field name="period" />
 
33
</form>"""
 
34
 
 
35
fields_fyear = {
 
36
    'period': {'string': 'Period', 'type': 'many2one', 'relation': 'account.period', 'required': True,},
 
37
}
 
38
 
 
39
form = """<?xml version="1.0"?>
 
40
<form string="Notification">
 
41
     <separator string="XML Flie has been Created."  colspan="4"/>
 
42
     <field name="msg" colspan="4" nolabel="1"/>
 
43
     <field name="file_save" />
 
44
</form>"""
 
45
 
 
46
fields = {
 
47
    'msg': {'string':'File created', 'type':'text', 'size':'100','readonly':True},
 
48
    'file_save':{'string': 'Save File',
 
49
        'type': 'binary',
 
50
        'readonly': True,},
 
51
}
 
52
 
 
53
 
 
54
class wizard_vat_declaration(wizard.interface):
 
55
 
 
56
    def _create_xml(self, cr, uid, data, context):
 
57
        list_of_tags=['00','01','02','03','45','46','47','48','49','54','55','56','57','59','61','62','63','64','71','81','82','83','84','85','86','87','91']
 
58
        pool_obj = pooler.get_pool(cr.dbname)
 
59
        #obj_company = pool_obj.get('res.company').browse(cr,uid,1)
 
60
        obj_company = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid).company_id
 
61
        user_cmpny = obj_company.name
 
62
        vat_no=obj_company.partner_id.vat
 
63
        if not vat_no:
 
64
            raise wizard.except_wizard(_('Data Insufficient'),_('No VAT Number Associated with Main Company!'))
 
65
 
 
66
        tax_ids = pool_obj.get('account.tax.code').search(cr,uid,[])
 
67
        ctx = context.copy()
 
68
        ctx['period_id'] = data['form']['period'] #added context here
 
69
        tax_info = pool_obj.get('account.tax.code').read(cr,uid,tax_ids,['code','sum_period'],context=ctx)
 
70
 
 
71
        address=post_code=city=''
 
72
        if not obj_company.partner_id.address:
 
73
                address=post_code=city=''
 
74
 
 
75
        city, post_code, address = pooler.get_pool(cr.dbname).get('res.company')._get_default_ad(obj_company.partner_id.address)
 
76
 
 
77
        obj_fyear = pool_obj.get('account.fiscalyear')
 
78
        year_id = obj_fyear.find(cr, uid)
 
79
        
 
80
        account_period=pool_obj.get('account.period').browse(cr, uid, data['form']['period'])
 
81
        current_year = account_period.fiscalyear_id.name
 
82
        period_code = account_period.code
 
83
 
 
84
        send_ref = user_cmpny
 
85
        if period_code:
 
86
            send_ref = send_ref + period_code
 
87
 
 
88
        data_of_file='<?xml version="1.0"?>\n<VATSENDING xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="MultiDeclarationTVA-NoSignature-14.xml">'
 
89
        data_of_file +='\n\t<DECLARER>\n\t\t<VATNUMBER>'+str(vat_no)+'</VATNUMBER>\n\t\t<NAME>'+str(obj_company.name)+'</NAME>\n\t\t<ADDRESS>'+address+'</ADDRESS>'
 
90
        data_of_file +='\n\t\t<POSTCODE>'+post_code+'</POSTCODE>\n\t\t<CITY>'+city+'</CITY>\n\t\t<SENDINGREFERENCE>'+send_ref+'</SENDINGREFERENCE>\n\t</DECLARER>'
 
91
        data_of_file +='\n\t<VATRECORD>\n\t\t<RECNUM>1</RECNUM>\n\t\t<VATNUMBER>'+str(vat_no)+'</VATNUMBER>\n\t\t<DPERIODE>\n\t\t\t'
 
92
 
 
93
        starting_month = account_period.date_start[5:7]
 
94
        ending_month = account_period.date_stop[5:7]
 
95
        if starting_month != ending_month:
 
96
            #starting month and ending month of selected period are not the same 
 
97
            #it means that the accounting isn't based on periods of 1 month but on quarters
 
98
            quarter = str(((int(starting_month) - 1) / 3) + 1)
 
99
            data_of_file += '<QUARTER>'+quarter+'</QUARTER>\n\t\t\t'
 
100
        else:
 
101
            data_of_file += '<MONTH>'+starting_month+'</MONTH>\n\t\t\t'
 
102
        data_of_file += '<YEAR>' + str(account_period.date_stop[:4]) + '</YEAR>\n\t\t</DPERIODE>\n\t\t<ASK RESTITUTION="NO" PAYMENT="NO"/>'
 
103
        data_of_file +='\n\t\t<DATA>\n\t\t\t<DATA_ELEM>'
 
104
 
 
105
        for item in tax_info:
 
106
            if item['code']:
 
107
                if item['code'] == '71-72':
 
108
                    item['code']='71'
 
109
                if item['code'] in list_of_tags:
 
110
                    data_of_file +='\n\t\t\t\t<D'+str(int(item['code'])) +'>' + str(int(item['sum_period']*100)) +  '</D'+str(int(item['code'])) +'>'
 
111
 
 
112
        data_of_file +='\n\t\t\t</DATA_ELEM>\n\t\t</DATA>\n\t</VATRECORD>\n</VATSENDING>'
 
113
        data['form']['msg']='Save the File with '".xml"' extension.'
 
114
        data['form']['file_save']=base64.encodestring(data_of_file)
 
115
        return data['form']
 
116
 
 
117
 
 
118
    states = {
 
119
        'init': {
 
120
            'actions': [],
 
121
            'result': {'type':'form', 'arch':form_fyear, 'fields':fields_fyear, 'state':[('end','Cancel'),('go','Create XML')]},
 
122
        },
 
123
        'go': {
 
124
            'actions': [_create_xml],
 
125
            'result': {'type':'form', 'arch':form, 'fields':fields, 'state':[('end','Ok')]},
 
126
        }
 
127
    }
 
128
 
 
129
wizard_vat_declaration('wizard.account.xml.vat.declaration')
 
130
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: