Amit Dodiya (OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/5.0-opw-381491-VatListing-ado into
lp:openobject-addons/5.0.
Requested reviews:
nel (nel-tinyerp)
Naresh(OpenERP) (nch-openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/5.0-opw-381491-VatListing-ado/+merge/91037
Hello,
Improve the Vat_List.xml file creation from wizard as per the new VAT format.
Thanks,
Amit
--
https://code.launchpad.net/~openerp-dev/openobject-addons/5.0-opw-381491-VatListing-ado/+merge/91037
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/5.0-opw-381491-VatListing-ado.
=== modified file 'l10n_be/company.py'
--- l10n_be/company.py 2010-04-06 09:41:18 +0000
+++ l10n_be/company.py 2012-02-01 10:01:48 +0000
@@ -21,6 +21,8 @@
##############################################################################
from osv import osv
+from osv import fields, osv
+
class res_company(osv.osv):
_inherit = "res.company"
@@ -42,4 +44,17 @@
return city, post_code, address, country_code
res_company()
+class vat_listing_clients(osv.osv):
+
+ _name = 'vat.listing.clients'
+ _columns = {
+ 'name': fields.char('Client Name', size=32),
+ 'vat': fields.char('VAT', size=64),
+ 'country': fields.char('Country', size=16),
+ 'amount': fields.float('Amount'),
+ 'turnover': fields.float('Turnover'),
+ }
+vat_listing_clients()
+
+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== modified file 'l10n_be/wizard/partner_vat_listing.py'
--- l10n_be/wizard/partner_vat_listing.py 2010-08-23 13:55:19 +0000
+++ l10n_be/wizard/partner_vat_listing.py 2012-02-01 10:01:48 +0000
@@ -26,6 +26,8 @@
import base64
from tools.translate import _
import tools
+from osv import fields, osv
+
form = """<?xml version="1.0"?>
<form string="Select Fiscal Year">
@@ -33,8 +35,6 @@
<newline/>
<field name="fyear" />
<newline/>
- <field name="mand_id" help="Should be provided when subscription of INTERVAT service is done"/>
- <newline/>
<field name="limit_amount" help="Limit under which the partners will not be included into the listing"/>
<newline/>
<field name="test_xml" help="Set the XML output as test file"/>
@@ -46,38 +46,73 @@
'limit_amount':{'string':'Limit Amount','type':'integer','required': True, },
'test_xml': {'string':'Test XML file', 'type':'boolean', },
}
+
msg_form = """<?xml version="1.0"?>
+ <form string="Select Fiscal Year">
+ <notebook colspan="4">
+ <page string="Details">
+ <field name="identification_type"/>
+ <newline/>
+ <field name="other" attrs="{'invisible':[('identification_type','!=','other')], 'required': [('identification_type','=','other')]}"/>
+ <label string="You can remove customers which you do not want in exported xml file" colspan="4"/>
+ <separator string="Customers" colspan="4"/>
+ <field name="partner_ids" colspan="4" nolabel="1" default_focus="1" height="200" width="500"/>
+ </page>
+ <page string="Comments">
+ <field name="comments" colspan="4" nolabel="1"/>
+ </page>
+ </notebook>
+ </form>"""
+
+msg_fields = {
+ 'partner_ids': {'string':'Clients','type':'many2many', 'relation':'vat.listing.clients'},
+ 'identification_type':{'string':"Identification Type ",'type':'selection','selection':[('tin','TIN'), ('nvat','NVAT'), ('other','Other')]},
+ 'other': {'string': 'QLF', 'type': 'text', 'size': 64},
+ 'comments': {'string': 'Comments', 'type': 'text', 'size' : 64},
+}
+
+msg_form_new = """<?xml version="1.0"?>
<form string="Notification">
<separator string="XML File has been Created." colspan="4"/>
<field name="msg" colspan="4" nolabel="1"/>
- <field name="file_save" />
+ <field name="file" />
</form>"""
-
-msg_fields = {
+msg_fields_new = {
'msg': {'string':'File created', 'type':'text', 'size':'100','readonly':True},
- 'file_save':{'string': 'Save File',
+ 'file':{'string': 'Save File',
'type': 'binary',
'readonly': True,},
}
+
class wizard_vat(wizard.interface):
+
+ def _check_data(self, cr, uid, data, context):
+ obj_cmpny = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid).company_id
+ company_vat = obj_cmpny.partner_id.vat
+ if not company_vat:
+ raise wizard.except_wizard(_('Data Insufficient'),_('No VAT Number Associated with Main Company!'))
+ return data['form']
def _create_xml(self, cr, uid, data, context):
datas=[]
seq_controlref = pooler.get_pool(cr.dbname).get('ir.sequence').get(cr, uid,'controlref')
seq_declarantnum = pooler.get_pool(cr.dbname).get('ir.sequence').get(cr, uid,'declarantnum')
obj_cmpny = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid).company_id
+ obj_vat_lclient = pooler.get_pool(cr.dbname).get('vat.listing.clients')
+
company_vat = obj_cmpny.partner_id.vat
- if not company_vat:
- raise wizard.except_wizard(_('Data Insufficient'),_('No VAT Number Associated with Main Company!'))
-
cref = company_vat + seq_controlref
dnum = cref + seq_declarantnum
+ company_vat = company_vat.replace(' ','').upper()
+ SenderId = company_vat[2:]
+ issued_by = company_vat[:2]
p_id_list = pooler.get_pool(cr.dbname).get('res.partner').search(cr,uid,[('vat_subjected','!=',False)])
if not p_id_list:
raise wizard.except_wizard(_('Data Insufficient!'),_('No partner has a VAT Number asociated with him.'))
+
obj_year=pooler.get_pool(cr.dbname).get('account.fiscalyear').browse(cr,uid,data['form']['fyear'])
period_ids = pooler.get_pool(cr.dbname).get('account.period').search(cr, uid, [('fiscalyear_id', '=', data['form']['fyear'])])
period = "("+','.join(map(lambda x: str(x), period_ids)) +")"
@@ -86,8 +121,10 @@
addr = pooler.get_pool(cr.dbname).get('res.partner').address_get(cr, uid, [obj_cmpny.partner_id.id], ['invoice'])
if addr.get('invoice',False):
ads=pooler.get_pool(cr.dbname).get('res.partner.address').browse(cr,uid,[addr['invoice']])[0]
-
+ email = ads.email or ''
+ phone = ads.phone or ''
zip_city = pooler.get_pool(cr.dbname).get('res.partner.address').get_city(cr,uid,ads.id)
+ zip = pooler.get_pool(cr.dbname).get('res.partner.address').browse(cr, uid, ads.id, context=context).zip or ''
if not zip_city:
zip_city = ''
if ads.street:
@@ -98,20 +135,60 @@
country = ads.country_id.code
sender_date = time.strftime('%Y-%m-%d')
+
+ annual_listing_data = {
+ 'identificationType': data['form']['identification_type'],
+ 'issued_by': issued_by,
+ 'other': data['form']['other'],
+ 'company_vat': company_vat,
+ 'comp_name': obj_cmpny.name,
+ 'street': street,
+ 'zip': zip,
+ 'city': zip_city,
+ 'country': country,
+ 'email': email,
+ 'phone': phone,
+ 'SenderId': SenderId,
+ 'period': obj_year.date_stop[:4],
+ 'comments': data['form']['comments'] or ''
+ }
+
comp_name = obj_cmpny.name
- data_file = '<?xml version="1.0"?>\n<VatList xmlns="http://www.minfin.fgov.be/VatList" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.minfin.fgov.be/VatList VatList.xml" RecipientId="VAT-ADMIN" SenderId="'+ str(company_vat) + '"'
- data_file +=' ControlRef="'+ cref + '" MandataireId="'+ data['form']['mand_id'] + '" SenderDate="'+ str(sender_date)+ '"'
- if data['form']['test_xml']:
- data_file += ' Test="0"'
- data_file += ' VersionTech="1.2">'
- data_file += '\n<AgentRepr DecNumber="1">\n\t<CompanyInfo>\n\t\t<VATNum>'+str(company_vat)+'</VATNum>\n\t\t<Name>'+ comp_name +'</Name>\n\t\t<Street>'+ street +'</Street>\n\t\t<CityAndZipCode>'+ zip_city +'</CityAndZipCode>'
- data_file += '\n\t\t<Country>'+ country +'</Country>\n\t</CompanyInfo>\n</AgentRepr>'
- data_comp = '\n<CompanyInfo>\n\t<VATNum>'+str(company_vat)+'</VATNum>\n\t<Name>'+ comp_name +'</Name>\n\t<Street>'+ street +'</Street>\n\t<CityAndZipCode>'+ zip_city +'</CityAndZipCode>\n\t<Country>'+ country +'</Country>\n</CompanyInfo>'
- data_period = '\n<Period>'+ obj_year.date_stop[:4] +'</Period>'
+ data_file = """<?xml version="1.0"?>
+ <ClientListingConsignment xmlns="http://www.minfin.fgov.be/ClientListingConsignment" ClientListingsNbr="1">
+ <Representative>
+ <RepresentativeID identificationType="%(identificationType)s" issuedBy="%(issued_by)s" otherQlf="%(other)s">%(company_vat)s</RepresentativeID>
+ <Name>%(comp_name)s</Name>
+ <Street>%(street)s</Street>
+ <PostCode>%(zip)s</PostCode>
+ <City>%(city)s</City>
+ <CountryCode>%(country)s</CountryCode>
+ <EmailAddress>%(email)s</EmailAddress>
+ <Phone>%(phone)s</Phone>
+ </Representative>
+ <RepresentativeReference></RepresentativeReference>
+ """ %(annual_listing_data)
+ data_comp = """
+ <ReplacedClientListing></ReplacedClientListing>
+ <Declarant>
+ <VATNumber xmlns="http://www.minfin.fgov.be/InputCommon">%(SenderId)s</VATNumber>
+ <Name>%(comp_name)s</Name>
+ <Street>%(street)s</Street>
+ <PostCode>%(zip)s</PostCode>
+ <City>%(city)s</City>
+ <CountryCode>%(country)s</CountryCode>
+ <EmailAddress>%(email)s</EmailAddress>
+ <Phone>%(phone)s</Phone>
+ </Declarant>
+ <Period>%(period)s</Period>
+ """ %(annual_listing_data)
+
error_message = []
for p_id in p_id_list:
- record = {} # this holds record per partner
+ record = {}
+ record['amount'] = 0
+ record['turnover'] = 0
obj_partner = pooler.get_pool(cr.dbname).get('res.partner').browse(cr,uid,p_id)
#This listing is only for customers located in belgium, that's the
@@ -149,17 +226,19 @@
#~ if len(record)<2:
#~ record.append('')
#~ error_message.append('Data Insufficient! : '+ 'The Partner "'+obj_partner.name + '"'' has no Invoice address!')
-
- record['amount'] = 0
- record['turnover'] = 0
-
- for item in line_info:
- if item[0]=='produit':
- record['turnover'] += item[1]
- else:
- record['amount'] += item[1]
+ listing_data = pooler.get_pool(cr.dbname).get('vat.listing.clients').browse(cr, uid, uid)
+ record['turnover'] += listing_data.turnover
+ record['amount'] += listing_data.amount
datas.append(record)
+ for partner in data['form']['partner_ids']:
+ if isinstance(partner, list) and partner:
+ datas.append(partner[2])
+ else:
+ client_data = obj_vat_lclient.browse(cr, uid, partner[2])
+ for i in client_data:
+ datas.append(i)
+
seq=0
data_clientinfo=''
sum_tax=0.00
@@ -167,31 +246,65 @@
if len(error_message):
data['form']['msg']='Exception : \n' +'-'*50+'\n'+ '\n'.join(error_message)
return data['form']
+ amount_data = {
+ 'seq': str(seq),
+ 'dnum': dnum,
+ 'sum_tax': str(0),
+ 'sum_turnover': str(0)}
for line in datas:
+ if not line['vat']:
+ raise wizard.except_wizard(_('Warning !'), _("Missing VAT ,Partner does not have a vat number"))
+ if not line['country']:
+ raise wizard.except_wizard(_('Warning !'), _("Missing Country ,Partner does not have a country"))
+ vat_issued = line['vat'][:2]
+ if vat_issued == 'BE':
+ vat_issued = ''
+ else:
+ vat_issued = vat_issued
if line['turnover'] < data['form']['limit_amount']:
continue
seq +=1
sum_tax +=line['amount']
sum_turnover +=line['turnover']
- data_clientinfo +='\n<ClientList SequenceNum="'+str(seq)+'">\n\t<CompanyInfo>\n\t\t<VATNum>'+line['vat'] +'</VATNum>\n\t\t<Country>'+tools.ustr(line['country']) +'</Country>\n\t</CompanyInfo>\n\t<Amount>'+str(int(line['amount'] * 100)) +'</Amount>\n\t<TurnOver>'+str(int(line['turnover'] * 100)) +'</TurnOver>\n</ClientList>'
+
+ amount_data.update({
+ 'seq': str(seq),
+ 'vat_issued': vat_issued,
+ 'only_vat': line['vat'].replace(' ','').upper()[2:],
+ 'turnover': str(int(round(line['turnover'] * 100))),
+ 'vat_amount': str(int(round(line['amount'] * 100))),
+ 'sum_tax': str(int(round(sum_tax * 100))),
+ 'sum_turnover': str(int(round(sum_turnover * 100))),
+ })
+
+ data_clientinfo += """
+ <Client SequenceNumber="%(seq)s">
+ <CompanyVATNumber issuedby="%(vat_issued)s">%(only_vat)s</CompanyVATNumber>
+ <TurnOver>%(turnover)s</TurnOver>
+ <VATAmount>%(vat_amount)s</VATAmount>
+ </Client>""" %(amount_data)
- data_decl ='\n<DeclarantList SequenceNum="1" DeclarantNum="'+ dnum + '" ClientNbr="'+ str(seq) +'" TurnOverSum="'+ str(int(sum_turnover * 100)) +'" TaxSum="'+ str(int(sum_tax * 100)) +'" />'
- data_file += data_decl + data_comp + str(data_period) + data_clientinfo + '\n</VatList>'
+ data_decl ='<ClientListing SequenceNumber="1" ClientsNbr="%(seq)s" DeclarantReference="%(dnum)s" TurnOverSum="%(sum_turnover)s" VATAmountSum="%(sum_tax)s">' %(amount_data)
+ data_file += data_decl + data_comp + data_clientinfo + '\n\t\t<FileAttachment></FileAttachment> \n\t\t<Comment>%(comments)s</Comment>\n\t</ClientListing>\n</ClientListingConsignment>' %(annual_listing_data)
data['form']['msg'] = 'Save the File with '".xml"' extension.'
- data['form']['file_save'] = base64.encodestring(data_file.encode('utf8'))
+ data['form']['name'] = 'vat_list.xml'
+ data['form']['file'] = base64.encodestring(data_file.encode('utf8'))
return data['form']
states = {
'init': {
'actions': [],
- 'result': {'type':'form', 'arch':form, 'fields':fields, 'state':[('end','Cancel'),('go','Create XML')]},
+ 'result': {'type':'form', 'arch':form, 'fields':fields, 'state':[('end','Cancel'),('go','View Client')]},
},
'go': {
+ 'actions': [_check_data],
+ 'result': {'type': 'form', 'arch':msg_form, 'fields':msg_fields, 'state':[('end','Close'),('create_file','Create XML')]}
+ },
+ 'create_file': {
'actions': [_create_xml],
- 'result': {'type':'form', 'arch':msg_form, 'fields':msg_fields, 'state':[('end','Ok')]},
+ 'result': {'type': 'form', 'arch':msg_form_new, 'fields':msg_fields_new, 'state':[('end','Close')]}
}
-
}
wizard_vat('list.vat.detail')
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp