1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
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.
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.
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/>.
21
##############################################################################
28
from tools.translate import _
30
form_fyear = """<?xml version="1.0"?>
31
<form string="Select Period">
32
<field name="period" />
36
'period': {'string': 'Period', 'type': 'many2one', 'relation': 'account.period', 'required': True,},
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" />
47
'msg': {'string':'File created', 'type':'text', 'size':'100','readonly':True},
48
'file_save':{'string': 'Save File',
54
class wizard_vat_declaration(wizard.interface):
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
64
raise wizard.except_wizard(_('Data Insufficient'),_('No VAT Number Associated with Main Company!'))
66
tax_ids = pool_obj.get('account.tax.code').search(cr,uid,[])
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)
71
address=post_code=city=''
72
if not obj_company.partner_id.address:
73
address=post_code=city=''
75
city, post_code, address = pooler.get_pool(cr.dbname).get('res.company')._get_default_ad(obj_company.partner_id.address)
77
obj_fyear = pool_obj.get('account.fiscalyear')
78
year_id = obj_fyear.find(cr, uid)
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
86
send_ref = send_ref + period_code
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'
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'
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>'
105
for item in tax_info:
107
if item['code'] == '71-72':
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'])) +'>'
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)
121
'result': {'type':'form', 'arch':form_fyear, 'fields':fields_fyear, 'state':[('end','Cancel'),('go','Create XML')]},
124
'actions': [_create_xml],
125
'result': {'type':'form', 'arch':form, 'fields':fields, 'state':[('end','Ok')]},
129
wizard_vat_declaration('wizard.account.xml.vat.declaration')
130
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: