[ADD] l10n_be: convert vat_listing and vat_intra wizard to osv_memory wizard

bzr revid: psi@tinyerp.co.in-20100401133812-zive4kwxdgwtirc4
This commit is contained in:
psi (Open ERP)
2010-04-01 19:08:12 +05:30
parent de3795e108
commit be891597ed
8 changed files with 335 additions and 287 deletions
+2
View File
@@ -51,6 +51,8 @@
'account_pcmn_belgium.xml',
'l10n_be_wizard.xml',
'wizard/l10n_be_account_vat_declaration_view.xml',
'wizard/l10n_be_vat_intra_view.xml',
'wizard/l10n_be_partner_vat_listing.xml',
'l10n_be_sequence.xml',
'fiscal_templates.xml',
'security/ir.model.access.csv'
-81
View File
@@ -2,90 +2,9 @@
<openerp>
<data>
<menuitem
id="menu_finance_belgian_statement"
name="Belgium Statements"
parent="account.menu_finance_legal_statement"/>
<wizard
string="Annual Listing of VAT-Subjected Customers"
model="res.partner"
name="list.vat.detail"
menu="False"
id="partner_wizard_vat"/>
<menuitem
name="Annual Listing of VAT-Subjected Customers"
parent="menu_finance_belgian_statement"
action="partner_wizard_vat"
type="wizard"
id="partner_wizard_vat_menu"/>
<!-- <wizard
string="Periodical VAT Declaration"
name="wizard.account.xml.vat.declaration"
menu="False"
id="wizard_xml_vat_declaration"/>
<menuitem
name="Periodical VAT Declaration"
parent="menu_finance_belgian_statement"
action="wizard_xml_vat_declaration"
type="wizard"
id="account_wizard_vat_declaration"/> -->
<wizard
string="Partner VAT intra"
model="res.partner"
name="vat.intra.xml"
menu="False"
id="partner_vat_intra"/>
<menuitem
name="Partner VAT intra"
parent="menu_finance_belgian_statement"
action="partner_vat_intra"
type="wizard"
id="partner_intra_vat_menu"/>
<record id="config_call_account_template" model="ir.actions.todo">
<field name="action_id" ref="account.action_wizard_multi_chart"/>
</record>
<!-- osv_memory for vat listing of clients -->
<record id="view_vat_listing" model="ir.ui.view">
<field name="name">step.vat.listing</field>
<field name="model">vat.listing.clients</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="VAT listing">
<field name="name"/>
<field name="vat"/>
<newline/>
<field name="country"/>
<newline/>
<field name="amount"/>
<field name="turnover"/>
</form>
</field>
</record>
<record id="view_vat_listing" model="ir.ui.view">
<field name="name">step.vat.listing</field>
<field name="model">vat.listing.clients</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="VAT listing">
<field name="name"/>
<field name="vat"/>
<newline/>
<field name="country"/>
<newline/>
<field name="amount"/>
<field name="turnover"/>
</tree>
</field>
</record>
</data>
</openerp>
+2 -2
View File
@@ -19,8 +19,8 @@
#
##############################################################################
import partner_vat_listing
import wizard_vat_intra
import l10_be_partner_vat_listing
import l10n_be_vat_intra
import l10n_be_account_vat_declaration
@@ -1,3 +1,6 @@
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# -*- coding: utf-8 -*-
##############################################################################
#
@@ -18,14 +21,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
import datetime
import base64
from tools.translate import _
import tools
import wizard
import pooler
from tools.translate import _
import tools
from osv import fields, osv
@@ -33,7 +33,7 @@ from osv import fields, osv
class vat_listing_clients(osv.osv_memory):
_name = 'vat.listing.clients'
_columns = {
'name': fields.char('Cleint Name', size=64),
'name': fields.char('Client Name', size=64),
'vat': fields.char('VAT', size=64),
'country': fields.char('Country', size=64),
'amount': fields.float('Amount'),
@@ -42,66 +42,23 @@ class vat_listing_clients(osv.osv_memory):
vat_listing_clients()
form = """<?xml version="1.0"?>
<form string="Select Fiscal Year">
<label string="This wizard will create an XML file for Vat details and total invoiced amounts per partner." colspan="4"/>
<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="Sets the XML output as test file"/>
</form>"""
class partner_vat(osv.osv_memory):
""" Vat Listing """
_name = "partner.vat"
fields = {
'fyear': {'string': 'Fiscal Year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True,},
'mand_id':{'string':'MandataireId','type':'char','size':'30','required': True,},
'limit_amount':{'string':'Limit Amount','type':'integer','required': True, },
'test_xml': {'string':'Test XML file', 'type':'boolean', },
}
client_form = """<?xml version="1.0"?>
<form string="Select Fiscal Year">
<label string="You can remove clients/partners which you do not want in exported xml file" colspan="4"/>
<separator string="Clients" colspan="4"/>
<field name="partners" colspan="4" width="600" height="250" widget="one2many" nolabel="1"/>
</form>"""
client_fields = {
'partners': {'string': 'Cleints', 'type': 'many2many', 'relation': 'vat.listing.clients', 'required': False, 'help': 'You can remove clients/partners which you do not want to show in xml file'},
}
msg_form = """<?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="name"/>
<newline/>
<field name="file_save" />
</form>"""
msg_fields = {
'name': {'string': 'File name', 'type':'char', 'size':'32'},
'msg': {'string':'File created', 'type':'text', 'size':'100','readonly':True},
'file_save':{'string': 'Save File',
'type': 'binary',
'readonly': True,},
}
class wizard_vat(wizard.interface):
def _get_partner(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
period = pool.get('account.period').search(cr, uid, [('fiscalyear_id', '=', data['form']['fyear'])])
p_id_list = pool.get('res.partner').search(cr,uid,[('vat_subjected','!=',False)])
def get_partner(self, cursor, user, ids, context={}):
obj_period = self.pool.get('account.period')
obj_partner = self.pool.get('res.partner')
obj_vat_lclient = self.pool.get('vat.listing.clients')
obj_model_data = self.pool.get('ir.model.data')
data = self.read(cursor, user, ids)[0]
period = obj_period.search(cursor, user, [('fiscalyear_id', '=', data['fyear'])], context=context)
p_id_list = obj_partner.search(cursor, user, [('vat_subjected','!=',False)], context=context)
if not p_id_list:
raise wizard.except_wizard(_('Data Insufficient!'),_('No partner has a VAT Number asociated with him.'))
raise osv.except_osv(_('Data Insufficient!'),_('No partner has a VAT Number asociated with him.'))
partners = []
records = []
for obj_partner in pool.get('res.partner').browse(cr, uid, p_id_list):
for obj_partner in obj_partner.browse(cursor, user, p_id_list, context=context):
record = {} # this holds record per partner
#This listing is only for customers located in belgium, that's the
@@ -114,8 +71,8 @@ class wizard_vat(wizard.interface):
break
if not go_ahead:
continue
cr.execute('select b.code,sum(credit)-sum(debit) from account_move_line l left join account_account a on (l.account_id=a.id) left join account_account_type b on (a.user_type=b.id) where b.code in %s and l.partner_id=%s and l.period_id=ANY(%s) group by b.code',(('produit','tax'),obj_partner.id,period,))
line_info = cr.fetchall()
cursor.execute('select b.code, sum(credit)-sum(debit) from account_move_line l left join account_account a on (l.account_id=a.id) left join account_account_type b on (a.user_type=b.id) where b.code in %s and l.partner_id=%s and l.period_id=ANY(%s) group by b.code',(('produit','tax'),obj_partner.id,period,))
line_info = cursor.fetchall()
if not line_info:
continue
@@ -127,7 +84,7 @@ class wizard_vat(wizard.interface):
#~addr = pool.get('res.partner').address_get(cr, uid, [obj_partner.id], ['invoice'])
#~ if addr.get('invoice',False):
#~ads=pool.get('res.partner.address').browse(cr,uid,[addr['invoice']])[0]
#~ads=pool.get('res.partner.address').browse(cr, uid, [addr['invoice']])[0]
#~ if ads.country_id:
#~ record.append(ads.country_id.code)
@@ -141,38 +98,77 @@ class wizard_vat(wizard.interface):
record['amount'] = 0
record['turnover'] = 0
record['name'] = obj_partner.name
for item in line_info:
if item[0]=='produit':
record['turnover'] += item[1]
else:
record['amount'] += item[1]
id_client = pool.get('vat.listing.clients').create(cr, uid, record)
id_client = obj_vat_lclient.create(cursor, user, record, context=context)
partners.append(id_client)
records.append(record)
context.update({'partner_ids': partners, 'fyear': data['fyear'], 'limit_amount': data['limit_amount'], 'mand_id':data['mand_id']})
model_data_ids = obj_model_data.search(cursor, user, [('model','=','ir.ui.view'), ('name','=','view_vat_listing')])
resource_id = obj_model_data.read(cursor, user, model_data_ids, fields=['res_id'])[0]['res_id']
return {
# 'domain': "[('id','in', ["+','.join(map(str,data['form']['invoice_ids']))+"])]",
'name': 'Vat Listing',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'partner.vat.list',
'views': [(resource_id,'form')],
'context': context,
'type': 'ir.actions.act_window',
'target': 'new',
}
return {'partners':partners}
_columns = {
'fyear': fields.many2one('account.fiscalyear','Fiscal Year', required=True),
'mand_id': fields.char('MandataireId', size=14, required=True, help="This identifies the representative of the sending company. This is a string of 14 characters"),
'limit_amount': fields.integer('Limit Amount', required=True),
'test_xml': fields.boolean('Test XML file', help="Sets the XML output as test file"),
}
partner_vat()
def _create_xml(self, cr, uid, data, context):
class partner_vat_list(osv.osv_memory):
""" Partner Vat Listing """
_name = "partner.vat.list"
_columns = {
'partner_ids': fields.many2many('vat.listing.clients', 'vat_partner_rel', 'vat_id', 'partner_id', 'Clients', required=False, help='You can remove clients/partners which you do not want to show in xml file'),
'name': fields.char('File Name', size=32),
'msg': fields.text('File created', size=64, readonly=True),
'file_save' : fields.binary('Save File', readonly=True),
}
def get_partners(self, cursor, user, context={}):
return context.get('partner_ids', [])
def create_xml(self, cursor, user, ids, context={}):
datas=[]
pool = pooler.get_pool(cr.dbname)
seq_controlref = pool.get('ir.sequence').get(cr, uid,'controlref')
seq_declarantnum = pool.get('ir.sequence').get(cr, uid,'declarantnum')
obj_cmpny = pool.get('res.users').browse(cr, uid, uid).company_id
obj_sequence = self.pool.get('ir.sequence')
obj_users = self.pool.get('res.users')
obj_partner = self.pool.get('res.partner')
obj_fyear = self.pool.get('account.fiscalyear')
obj_addr = self.pool.get('res.partner.address')
obj_vat_lclient = self.pool.get('vat.listing.clients')
obj_model_data = self.pool.get('ir.model.data')
seq_controlref = obj_sequence.get(cursor, user, 'controlref')
seq_declarantnum = obj_sequence.get(cursor, user, 'declarantnum')
obj_cmpny = obj_users.browse(cursor, user, user, context=context).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!'))
raise osv.except_osv(_('Data Insufficient'),_('No VAT Number Associated with Main Company!'))
cref = company_vat + seq_controlref
dnum = cref + seq_declarantnum
obj_year=pool.get('account.fiscalyear').browse(cr,uid,data['form']['fyear'])
obj_year= obj_fyear.browse(cursor, user, context['fyear'], context=context)
street = zip_city = country = ''
addr = pool.get('res.partner').address_get(cr, uid, [obj_cmpny.partner_id.id], ['invoice'])
addr = obj_partner.address_get(cursor, user, [obj_cmpny.partner_id.id], ['invoice'])
if addr.get('invoice',False):
ads=pool.get('res.partner.address').browse(cr,uid,[addr['invoice']])[0]
ads = obj_addr.browse(cursor, user, [addr['invoice']], context=context)[0]
zip_city = pool.get('res.partner.address').get_city(cr,uid,ads.id)
zip_city = obj_addr.get_city(cursor, user, ads.id)
if not zip_city:
zip_city = ''
if ads.street:
@@ -185,8 +181,8 @@ class wizard_vat(wizard.interface):
sender_date = time.strftime('%Y-%m-%d')
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="'+ tools.ustr(data['form']['mand_id']) + '" SenderDate="'+ str(sender_date)+ '"'
if data['form']['test_xml']:
data_file +=' ControlRef="'+ cref + '" MandataireId="'+ tools.ustr(context['mand_id']) + '" SenderDate="'+ str(sender_date)+ '"'
if ['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>'+tools.ustr(obj_cmpny.name)+'</Name>\n\t\t<Street>'+ tools.ustr(street) +'</Street>\n\t\t<CityAndZipCode>'+ tools.ustr(zip_city) +'</CityAndZipCode>'
@@ -194,25 +190,24 @@ class wizard_vat(wizard.interface):
data_comp = '\n<CompanyInfo>\n\t<VATNum>'+str(company_vat)+'</VATNum>\n\t<Name>'+tools.ustr(obj_cmpny.name)+'</Name>\n\t<Street>'+ tools.ustr(street) +'</Street>\n\t<CityAndZipCode>'+ tools.ustr(zip_city) +'</CityAndZipCode>\n\t<Country>'+ tools.ustr(country) +'</Country>\n</CompanyInfo>'
data_period = '\n<Period>'+ tools.ustr(obj_year.date_stop[:4]) +'</Period>'
error_message = []
for partner in data['form']['partners']:
data = self.read(cursor, user, ids)[0]
for partner in data['partner_ids']:
if isinstance(partner, list) and partner:
datas.append(partner[2])
else:
client_data = pool.get('vat.listing.clients').read(cr, uid, partner, context=context)
client_data = obj_vat_lclient.read(cursor, user, partner, context=context)
datas.append(client_data)
seq=0
data_clientinfo=''
sum_tax=0.00
sum_turnover=0.00
if len(error_message):
data['form']['msg']='Exception : \n' +'-'*50+'\n'+ '\n'.join(error_message)
return data['form']
msg ='Exception : \n' +'-'*50+'\n'+ '\n'.join(error_message)
return msg
for line in datas:
if not line:
continue
if line['turnover'] < data['form']['limit_amount']:
if line['turnover'] < context['limit_amount']:
continue
seq +=1
sum_tax +=line['amount']
@@ -221,28 +216,16 @@ class wizard_vat(wizard.interface):
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 += tools.ustr(data_decl) + tools.ustr(data_comp) + tools.ustr(data_period) + tools.ustr(data_clientinfo) + '\n</VatList>'
msg = 'Save the File with '".xml"' extension.'
file_save = base64.encodestring(data_file.encode('utf8'))
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'
return data['form']
self.write(cursor, user, ids, {'file_save':file_save, 'msg':msg, 'name':'vat_list.xml'}, context=context)
return True
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':form, 'fields':fields, 'state':[('end','Cancel', 'gtk-cancel'),('go_step','View Clients', 'gtk-ok')]},
},
'go_step': {
'actions': [_get_partner],
'result': {'type':'form', 'arch':client_form, 'fields':client_fields, 'state':[('end','Cancel', 'gtk-cancel'),('go','Create XML', 'gtk-ok')]},
},
'go': {
'actions': [_create_xml],
'result': {'type':'form', 'arch':msg_form, 'fields':msg_fields, 'state':[('end','Ok', 'gtk-cancel')]},
}
_defaults={
'partner_ids': get_partners
}
}
partner_vat_list()
wizard_vat('list.vat.detail')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -15,7 +15,7 @@
<form string="Select Period">
<group colspan="4" >
<field name="period_id" select="1"/>
<button colspan="1" name="create_xml" string="Create XML" type="object" default_focus="1"/>
<button colspan="1" name="create_xml" string="Create XML" type="object" default_focus="1" icon="gtk-execute"/>
</group>
<separator string="XML Flie has been Created." colspan="4"/>
<group colspan="4" >
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<menuitem
id="menu_finance_belgian_statement"
name="Belgium Statements"
parent="account.menu_finance_legal_statement"/>
<record id="view_partner_vat_listing" model="ir.ui.view">
<field name="name">Partner VAT Listing</field>
<field name="model">partner.vat</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Select Fiscal Year">
<label string="This wizard will create an XML file for Vat details and total invoiced amounts per partner." colspan="4"/>
<newline/>
<field name="fyear" />
<newline/>
<field name="mand_id"/>
<newline/>
<field name="limit_amount"/>
<newline/>
<field name="test_xml"/>
<separator colspan="4"/>
<group colspan="4" >
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button colspan="1" name="get_partner" string="View Client" type="object" default_focus="1" icon="terp-partner"/>
</group>
</form>
</field>
</record>
<record id="action_partner_vat_listing" model="ir.actions.act_window">
<field name="name">Partner VAT Listing</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">partner.vat</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_partner_vat_listing"/>
<field name="target">new</field>
</record>
<menuitem
name="Annual Listing of VAT-Subjected Customers"
parent="menu_finance_belgian_statement"
action="action_partner_vat_listing"
id="partner_vat_listing"/>
<record id="view_vat_listing" model="ir.ui.view">
<field name="name">Vat Listing</field>
<field name="model">partner.vat.list</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Select Fiscal Year" >
<label string="You can remove clients/partners which you do not want in exported xml file" colspan="4"/>
<separator string="Clients" colspan="4"/>
<field name="partner_ids" colspan="4" nolabel="1"/>
<separator colspan="4"/>
<group colspan="4" >
<button colspan="1" name="create_xml" string="Create XML" type="object" default_focus="1" icon="gtk-execute"/>
</group>
<separator string="XML File has been Created." colspan="4"/>
<field name="msg" colspan="4" nolabel="1"/>
<field name="name"/>
<newline/>
<field name="file_save" />
<separator colspan="4"/>
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
</form>
</field>
</record>
<!-- osv_memory for vat listing of clients -->
<record id="view_vat_listing_form" model="ir.ui.view">
<field name="name">step.vat.listing</field>
<field name="model">vat.listing.clients</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="VAT listing">
<field name="name"/>
<field name="vat"/>
<newline/>
<field name="country"/>
<newline/>
<field name="amount"/>
<field name="turnover"/>
</form>
</field>
</record>
<record id="view_vat_listing_tree" model="ir.ui.view">
<field name="name">step.vat.listing</field>
<field name="model">vat.listing.clients</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="VAT listing">
<field name="name"/>
<field name="vat"/>
<newline/>
<field name="country"/>
<newline/>
<field name="amount"/>
<field name="turnover"/>
</tree>
</field>
</record>
</data>
</openerp>
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
@@ -15,92 +15,72 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import wizard
from osv import osv, fields
import time
import datetime
import pooler
import base64
form_intra = """<?xml version="1.0"?>
<form string="Partner VAT Intra">
<notebook>
<page string="General Information">
<label string="This wizard will create an XML file for Vat Intra" colspan="4"/>
<newline/>
<field name="fyear" />
<newline/>
<field name="mand_id" help="This identifies the representative of the sending company. This is a string of 14 characters"/>
<newline/>
<field name="trimester" help="It will be the first digit of period" />
<newline/>
<field name="test_xml" help="Sets the XML output as test file"/>
</page>
<page string="European Countries">
<field name="country_ids" colspan="4" nolabel="1" />
</page>
</notebook>
</form>"""
fields_intra = {
'trimester': {'string': 'Trimester Number', 'type': 'selection', 'selection':[
('1','Jan/Feb/Mar'),
('2','Apr/May/Jun'),
('3','Jul/Aug/Sep'),
('4','Oct/Nov/Dec')], 'required': True},
'test_xml': {'string':'Test XML file', 'type':'boolean'},
'mand_id':{'string':'MandataireId','type':'char','size':'14','required': True},
'fyear': {'string': 'Fiscal Year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True},
'country_ids': {
'string': 'European Countries',
'type': 'many2many',
'relation': 'res.country',
'required': False
},
}
msg_form = """<?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" />
</form>"""
msg_fields = {
'msg': {'string':'File created', 'type':'text', 'size':'100','readonly':True},
'file_save':{'string': 'Save File',
'type': 'binary',
'readonly': True,},
}
class partner_vat_intra(osv.osv_memory):
class parter_vat_intra(wizard.interface):
""" Partner Vat Intra"""
_name = "partner.vat.intra"
def _get_europe_country(self, cr, uid, data, context):
country_ids = pooler.get_pool(cr.dbname).get('res.country').search(cr, uid, [('code', 'in', ['AT', 'BG', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB'])])
return {'country_ids': country_ids}
def _get_europe_country(self, cursor, user, context={}):
obj_country = self.pool.get('res.country')
country_ids = obj_country.search(cursor, user, [('code', 'in', ['AT', 'BG', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB'])])
return country_ids
_columns = {
'trimester': fields.selection(
[('1','Jan/Feb/Mar'),
('2','Apr/May/Jun'),
('3','Jul/Aug/Sep'),
('4','Oct/Nov/Dec')],
'Trimester Number', required=True, help="It will be the first digit of period"),
'test_xml': fields.boolean('Test XML file', help="Sets the XML output as test file"),
'mand_id' : fields.char('MandataireId', size=14, required=True, help="This identifies the representative of the sending company. This is a string of 14 characters"),
'fyear': fields.many2one('account.fiscalyear','Fiscal Year', required=True),
'msg': fields.text('File created', size=64, readonly=True),
'file_save' : fields.binary('Save File', readonly=True),
'country_ids': fields.many2many('res.country', 'vat_country_rel', 'vat_id', 'country_id', 'European Countries'),
}
_defaults = {
'country_ids': _get_europe_country,
}
def create_xml(self, cursor, user, ids, context):
obj_user = self.pool.get('res.users')
obj_fyear = self.pool.get('account.fiscalyear')
obj_sequence = self.pool.get('ir.sequence')
obj_partner = self.pool.get('res.partner')
obj_partner_add = self.pool.get('res.partner.address')
data_cmpny = obj_user.browse(cursor, user, user).company_id
data = self.read(cursor, user, ids)[0]
data_fiscal = obj_fyear.browse(cursor, user, data['fyear'], context=context)
def _create_xml(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
data_cmpny = pool.get('res.users').browse(cr, uid, uid).company_id
data_fiscal = pool.get('account.fiscalyear').browse(cr,uid,data['form']['fyear'])
company_vat = data_cmpny.partner_id.vat
if not company_vat:
raise wizard.except_wizard('Data Insufficient','No VAT Number Associated with Main Company!')
raise osv.except_osv(_('Data Insufficient'),_('No VAT Number Associated with Main Company!'))
seq_controlref = pool.get('ir.sequence').get(cr, uid,'controlref')
seq_declarantnum = pool.get('ir.sequence').get(cr, uid,'declarantnum')
seq_controlref = obj_sequence.get(cursor, user, 'controlref')
seq_declarantnum = obj_sequence.get(cursor, user, 'declarantnum')
cref = company_vat + seq_controlref
dnum = cref + seq_declarantnum
if len(data_fiscal.date_start.split('-')[0]) < 4:
raise wizard.except_wizard('Data Insufficient','Trimester year should be length of 4 digits!')
period_trimester = data['form']['trimester'] + data_fiscal.date_start.split('-')[0]
raise osv.except_osv(_('Data Insufficient'),_('Trimester year should be length of 4 digits!'))
period_trimester = data['trimester'] + data_fiscal.date_start.split('-')[0]
street = zip_city = country = ''
addr = pool.get('res.partner').address_get(cr, uid, [data_cmpny.partner_id.id], ['invoice'])
addr = obj_partner.address_get(cursor, user, [data_cmpny.partner_id.id], ['invoice'])
if addr.get('invoice',False):
ads = pool.get('res.partner.address').browse(cr,uid,[addr['invoice']])[0]
ads = obj_partner_add.browse(cursor, user, [addr['invoice']])[0]
zip_city = (ads.city or '') + ' ' + (ads.zip or '')
if zip_city== ' ':
zip_city = ''
@@ -114,8 +94,8 @@ class parter_vat_intra(wizard.interface):
sender_date = time.strftime('%Y-%m-%d')
data_file = '<?xml version="1.0"?>\n<VatIntra xmlns="http://www.minfin.fgov.be/VatIntra" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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 +=' ControlRef="' + cref + '" MandataireId="' + data['mand_id'] + '" SenderDate="'+ str(sender_date)+ '"'
if data['test_xml']:
data_file += ' Test="1"'
data_file += ' VersionTech="1.2">'
data_file +='\n\t<AgentRepr DecNumber="1">\n\t\t<CompanyInfo>\n\t\t\t<VATNum>' + str(company_vat)+'</VATNum>\n\t\t\t<Name>'+str(data_cmpny.name)+'</Name>\n\t\t\t<Street>'+ str(street) +'</Street>\n\t\t\t<CityAndZipCode>'+ str(zip_city) +'</CityAndZipCode>'
@@ -127,35 +107,35 @@ class parter_vat_intra(wizard.interface):
error_message = []
seq = 0
amount_sum = 0
p_id_list = pool.get('res.partner').search(cr,uid,[('vat','!=',False)])
p_id_list = obj_partner.search(cursor, user, [('vat','!=',False)])
if not p_id_list:
raise wizard.except_wizard('Data Insufficient!','No partner has a VAT Number asociated with him.')
raise osv.except_osv(_('Data Insufficient!'),_('No partner has a VAT Number asociated with him.'))
nb_period = len(data_fiscal.period_ids)
fiscal_periods = data_fiscal.period_ids
if data['form']['trimester'] == '1':
if data['trimester'] == '1':
if nb_period == 12:
start_date = fiscal_periods[0].date_start
end_date = fiscal_periods[2].date_stop
elif nb_period == 4:
start_date = fiscal_periods[0].date_start
end_date = fiscal_periods[0].date_stop
elif data['form']['trimester'] == '2':
elif data['trimester'] == '2':
if nb_period == 12:
start_date = fiscal_periods[3].date_start
end_date = fiscal_periods[5].date_stop
elif nb_period == 4:
start_date = fiscal_periods[1].date_start
end_date = fiscal_periods[1].date_stop
elif data['form']['trimester'] == '3':
elif data['trimester'] == '3':
if nb_period == 12:
start_date = fiscal_periods[6].date_start
end_date = fiscal_periods[8].date_stop
elif nb_period == 4:
start_date = fiscal_periods[2].date_start
end_date = fiscal_periods[2].date_stop
elif data['form']['trimester'] == '4':
elif data['trimester'] == '4':
if nb_period == 12:
start_date = fiscal_periods[9].date_start
end_date = fiscal_periods[11].date_stop
@@ -168,19 +148,19 @@ class parter_vat_intra(wizard.interface):
for p_id in p_id_list:
list_partner = []
partner = pool.get('res.partner').browse(cr, uid, p_id)
partner = obj_partner.browse(cursor, user, p_id, context=context)
go_ahead = False
country_code = ''
for ads in partner.address:
if ads.type == 'default' and (ads.country_id and ads.country_id.id in data['form']['country_ids'][0][2]):
if ads.type == 'default' and (ads.country_id and ads.country_id.id in data['country_ids']):
go_ahead = True
country_code = ads.country_id.code
break
if not go_ahead:
continue
cr.execute('select sum(debit)-sum(credit) as amount from account_move_line l left join account_account a on (l.account_id=a.id) where a.type in ('"'receivable'"') and l.partner_id=%%s and l.date between %s' % (period,), (p_id,))
res = cr.dictfetchall()
cursor.execute('select sum(debit)-sum(credit) as amount from account_move_line l left join account_account a on (l.account_id=a.id) where a.type in ('"'receivable'"') and l.partner_id=%%s and l.date between %s' % (period,), (p_id,))
res = cursor.dictfetchall()
list_partner.append(res[0]['amount'])
list_partner.append('T') #partner.ref ...should be check
list_partner.append(partner.vat)
@@ -202,8 +182,8 @@ class parter_vat_intra(wizard.interface):
record[p_id] = list_partner
if len(error_message):
data['form']['msg'] = 'Exception : \n' +'-'*50+'\n'+ '\n'.join(error_message)
return data['form']
data['msg'] = 'Exception : \n' +'-'*50+'\n'+ '\n'.join(error_message)
return data['msg']
data_clientinfo = ''
for r in record:
@@ -215,18 +195,11 @@ class parter_vat_intra(wizard.interface):
amount_sum = int(amount_sum)
data_decl = '\n\t<DeclarantList SequenceNum="1" DeclarantNum="'+ dnum + '" ClientNbr="'+ str(seq) +'" AmountSum="'+ str(amount_sum) +'" >'
data_file += str(data_decl) + str(data_comp) + str(data_period) + str(data_clientinfo) + '\n\t</DeclarantList>\n</VatIntra>'
data['form']['msg'] = 'Save the File with '".xml"' extension.'
data['form']['file_save'] = base64.encodestring(data_file)
return data['form']
data['msg'] = 'XML Flie has been Created. Save the File with '".xml"' extension.'
data['file_save'] = base64.encodestring(data_file)
self.write(cursor, user, ids, {'file_save':data['file_save'], 'msg':data['msg']}, context=context)
return True
states = {
'init': {
'actions': [_get_europe_country],
'result': {'type': 'form', 'arch':form_intra, 'fields': fields_intra, 'state':[('end','Cancel', 'gtk-cancel'),('go','Create XML', 'gtk-ok') ]}
},
'go': {
'actions': [_create_xml],
'result': {'type':'form', 'arch':msg_form, 'fields':msg_fields, 'state':[('end','Ok', 'gtk-cancel')]},
}
}
parter_vat_intra('vat.intra.xml')
partner_vat_intra()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<menuitem
id="menu_finance_belgian_statement"
name="Belgium Statements"
parent="account.menu_finance_legal_statement"/>
<record id="view_vat_intra" model="ir.ui.view">
<field name="name">Partner VAT intra</field>
<field name="model">partner.vat.intra</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Partner VAT intra">
<notebook>
<page string="General Information">
<label string="This wizard will create an XML file for Vat Intra" colspan="4"/>
<newline/>
<field name="fyear" />
<newline/>
<field name="mand_id"/>
<newline/>
<field name="trimester"/>
<newline/>
<field name="test_xml"/>
</page>
<page string="European Countries">
<field name="country_ids" colspan="4" nolabel="1" />
</page>
</notebook>
<newline/>
<button colspan="1" name="create_xml" string="Create XML" type="object" default_focus="1" icon="gtk-execute"/>
<separator colspan="4"/>
<group colspan="4" >
<field name="msg" nolabel="1" colspan="4"/>
<field name="file_save" readonly="True"/>
</group>
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
</form>
</field>
</record>
<record id="action_vat_intra" model="ir.actions.act_window">
<field name="name">Partner Vat Intra</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">partner.vat.intra</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_vat_intra"/>
<field name="target">new</field>
</record>
<menuitem
name="Partner VAT intra"
parent="menu_finance_belgian_statement"
action="action_vat_intra"
id="l10_be_vat_intra"/>
</data>
</openerp>