[MERGE] l10n_be: rewrite wizard Annual Listing of VAT
bzr revid: rco@openerp.com-20120201102133-kdu1ajkbpxoyqe5r
This commit is contained in:
commit
32bfeb684a
|
@ -23,11 +23,35 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
import base64
|
||||
from tools.translate import _
|
||||
from osv import fields, osv
|
||||
|
||||
class vat_listing_clients(osv.osv_memory):
|
||||
_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'),
|
||||
}
|
||||
|
||||
def name_get(self, cr, uid, ids, context=None):
|
||||
res = self.read(cr, uid, ids, ['name', 'vat'], context=context, load='_classic_write')
|
||||
return [(r['id'], '%s - %s' % (r['name'] or '', r['vat'] or '')) for r in res]
|
||||
|
||||
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
|
||||
args.append(['id', 'in', context['partner_ids']])
|
||||
client_ids = self.search(cr, uid, [('vat', '=', name)] + args, limit=limit, context=context)
|
||||
if not client_ids:
|
||||
client_ids = self.search(cr, uid, [('name', 'ilike', name)] + args, limit=limit, context=context)
|
||||
return self.name_get(cr, uid, client_ids, context=context)
|
||||
|
||||
vat_listing_clients()
|
||||
|
||||
class partner_vat_13(osv.osv_memory):
|
||||
""" Vat Listing """
|
||||
_name = "partner.vat_13"
|
||||
|
@ -98,39 +122,42 @@ class partner_vat_13(osv.osv_memory):
|
|||
'context': context,
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
}
|
||||
|
||||
_columns = {
|
||||
'year': fields.char('Year', size=4, required=True),
|
||||
'limit_amount': fields.integer('Limit Amount', required=True),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_defaults={
|
||||
'year': lambda *a: str(int(time.strftime('%Y'))-1),
|
||||
'limit_amount': 250,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
partner_vat_13()
|
||||
|
||||
class partner_vat_list_13(osv.osv_memory):
|
||||
|
||||
""" Partner Vat Listing """
|
||||
_name = "partner.vat.list_13"
|
||||
_columns = {
|
||||
# TODO the referenced model has been deleted at revno 4672.1.2.
|
||||
#'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'),
|
||||
'partner_ids': fields.many2many('vat.listing.clients', 'vat_partner_rel', 'vat_id', 'partner_id', 'Clients', 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),
|
||||
}
|
||||
'identification_type': fields.selection([('tin','TIN'), ('nvat','NVAT'), ('other','Other')], 'Identification Type', required=True),
|
||||
'other': fields.char('Other Qlf', size=16, help="Description of a Identification Type"),
|
||||
'comments': fields.text('Comments'),
|
||||
}
|
||||
|
||||
def _get_partners(self, cursor, user, context=None):
|
||||
return context.get('partner_ids', [])
|
||||
|
||||
_defaults={
|
||||
# TODO the referenced model has been deleted at revno 4672.1.2.
|
||||
# 'partner_ids': _get_partners
|
||||
}
|
||||
'partner_ids': _get_partners,
|
||||
'identification_type' : 'tin',
|
||||
}
|
||||
|
||||
def create_xml(self, cursor, user, ids, context=None):
|
||||
datas = []
|
||||
|
@ -151,35 +178,83 @@ class partner_vat_list_13(osv.osv_memory):
|
|||
|
||||
company_vat = company_vat.replace(' ','').upper()
|
||||
SenderId = company_vat[2:]
|
||||
issued_by = company_vat[:2]
|
||||
cref = SenderId + seq_controlref
|
||||
dnum = cref + seq_declarantnum
|
||||
#obj_year= obj_fyear.browse(cursor, user, context['fyear'], context=context)
|
||||
street = zip_city = country = ''
|
||||
street = city = country = ''
|
||||
addr = obj_partner.address_get(cursor, user, [obj_cmpny.partner_id.id], ['invoice'])
|
||||
if addr.get('invoice',False):
|
||||
ads = obj_addr.browse(cursor, user, [addr['invoice']], context=context)[0]
|
||||
phone = ads.phone or ''
|
||||
email = ads.email or ''
|
||||
name = ads.name or ''
|
||||
|
||||
zip_city = obj_addr.get_city(cursor, user, ads.id)
|
||||
if not zip_city:
|
||||
zip_city = ''
|
||||
city = obj_addr.get_city(cursor, user, ads.id)
|
||||
zip = obj_addr.browse(cursor, user, ads.id, context=context).zip or ''
|
||||
if not city:
|
||||
city = ''
|
||||
if ads.street:
|
||||
street = ads.street
|
||||
street = ads.street + ' '
|
||||
if ads.street2:
|
||||
street += ads.street2
|
||||
if ads.country_id:
|
||||
country = ads.country_id.code
|
||||
|
||||
data = self.read(cursor, user, ids)[0]
|
||||
other = data['other'] or ''
|
||||
sender_date = time.strftime('%Y-%m-%d')
|
||||
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" RecipientId="VAT-ADMIN" SenderId="'+ SenderId + '"'
|
||||
data_file +=' ControlRef="'+ cref + '" MandataireId="'+ cref + '" SenderDate="'+ str(sender_date)+ '"'
|
||||
data_file += ' VersionTech="1.3">'
|
||||
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>'+SenderId+'</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>' + context['year'] +'</Period>'
|
||||
|
||||
annual_listing_data = {
|
||||
'identificationType': data['identification_type'].upper(),
|
||||
'issued_by': issued_by,
|
||||
'other': other,
|
||||
'company_vat': company_vat,
|
||||
'comp_name': comp_name,
|
||||
'street': street,
|
||||
'zip': zip,
|
||||
'city': city,
|
||||
'country': country,
|
||||
'email': email,
|
||||
'phone': phone,
|
||||
'SenderId': SenderId,
|
||||
'period': context['year'],
|
||||
'comments': data['comments'] or ''
|
||||
}
|
||||
|
||||
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 = []
|
||||
data = self.read(cursor, user, ids)[0]
|
||||
|
||||
for partner in data['partner_ids']:
|
||||
if isinstance(partner, list) and partner:
|
||||
datas.append(partner[2])
|
||||
|
@ -187,12 +262,23 @@ class partner_vat_list_13(osv.osv_memory):
|
|||
client_data = obj_vat_lclient.read(cursor, user, partner, context=context)
|
||||
datas.append(client_data)
|
||||
seq = 0
|
||||
data_clientinfo = ''
|
||||
data_client_info = ''
|
||||
sum_tax = 0.00
|
||||
sum_turnover = 0.00
|
||||
if len(error_message):
|
||||
return 'Exception : \n' +'-'*50+'\n'+ '\n'.join(error_message)
|
||||
amount_data = {
|
||||
'seq': str(seq),
|
||||
'dnum': dnum,
|
||||
'sum_tax': str(0),
|
||||
'sum_turnover': str(0),
|
||||
}
|
||||
for line in datas:
|
||||
vat_issued = line['vat'][:2]
|
||||
if vat_issued == 'BE':
|
||||
vat_issued = ''
|
||||
else:
|
||||
vat_issued = vat_issued
|
||||
if not line:
|
||||
continue
|
||||
if line['turnover'] < context['limit_amount']:
|
||||
|
@ -200,38 +286,67 @@ class partner_vat_list_13(osv.osv_memory):
|
|||
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'].replace(' ','').upper()[2:] +'</VATNum>\n\t\t<Country>' + line['country'] +'</Country>\n\t</CompanyInfo>\n\t<Amount>'+str(int(round(line['amount'] * 100))) +'</Amount>\n\t<TurnOver>'+str(int(round(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))),
|
||||
})
|
||||
# Turnover and Farmer tags are not included
|
||||
data_client_info += """
|
||||
<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(round(sum_turnover * 100))) +'" TaxSum="'+ str(int(round(sum_tax * 100))) +'">'
|
||||
data_file += data_decl + data_comp + str(data_period) + data_clientinfo + '\n</DeclarantList>\n</VatList>'
|
||||
data_begin = """
|
||||
<ClientListing SequenceNumber="1" ClientsNbr="%(seq)s" DeclarantReference="%(dnum)s"
|
||||
TurnOverSum="%(sum_turnover)s" VATAmountSum="%(sum_tax)s">
|
||||
""" % amount_data
|
||||
|
||||
data_end = """
|
||||
<FileAttachment></FileAttachment>
|
||||
<Comment>%(comments)s</Comment>
|
||||
</ClientListing>
|
||||
</ClientListingConsignment>
|
||||
""" % annual_listing_data
|
||||
|
||||
data_file += data_begin + data_comp + data_client_info + data_end
|
||||
msg = 'Save the File with '".xml"' extension.'
|
||||
file_save = base64.encodestring(data_file.encode('utf8'))
|
||||
self.write(cursor, user, ids, {'file_save':file_save, 'msg':msg, 'name':'vat_list.xml'}, context=context)
|
||||
return True
|
||||
|
||||
def print_vatlist(self, cursor, user, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
obj_vat_lclient = self.pool.get('vat.listing.clients')
|
||||
client_datas = []
|
||||
data = self.read(cursor, user, ids)[0]
|
||||
for partner in data['partner_ids']:
|
||||
if isinstance(partner, list) and partner:
|
||||
client_datas.append(partner[2])
|
||||
else:
|
||||
client_data = obj_vat_lclient.read(cursor, user, partner, context=context)
|
||||
client_datas.append(client_data)
|
||||
|
||||
datas = {'ids': []}
|
||||
datas['model'] = 'res.company'
|
||||
datas['year'] = context['year']
|
||||
datas['limit_amount'] = context['limit_amount']
|
||||
datas['client_datas'] = client_datas
|
||||
return {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'partner.vat.listing.print',
|
||||
'datas': datas,
|
||||
}
|
||||
|
||||
# Not fully implemented
|
||||
|
||||
# def print_vatlist(self, cursor, user, ids, context=None):
|
||||
# if context is None:
|
||||
# context = {}
|
||||
# obj_vat_lclient = self.pool.get('vat.listing.clients')
|
||||
# client_datas = []
|
||||
# data = self.read(cursor, user, ids)[0]
|
||||
# for partner in data['partner_ids']:
|
||||
# if isinstance(partner, list) and partner:
|
||||
# client_datas.append(partner[2])
|
||||
# else:
|
||||
# client_data = obj_vat_lclient.read(cursor, user, partner, context=context)
|
||||
# client_datas.append(client_data)
|
||||
#
|
||||
# datas = {'ids': []}
|
||||
# datas['model'] = 'res.company'
|
||||
# datas['year'] = context['year']
|
||||
# datas['limit_amount'] = context['limit_amount']
|
||||
# datas['client_datas'] = client_datas
|
||||
# return {
|
||||
# 'type': 'ir.actions.report.xml',
|
||||
# 'report_name': 'partner.vat.listing.print',
|
||||
# 'datas': datas,
|
||||
# }
|
||||
|
||||
partner_vat_list_13()
|
||||
|
||||
|
|
|
@ -1,63 +1,71 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_partner_vat_listing_13" model="ir.ui.view">
|
||||
<field name="name">Partner VAT Listing</field>
|
||||
<field name="model">partner.vat_13</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Partner VAT Listing">
|
||||
<label string="This wizard will create an XML file for VAT details and total invoiced amounts per partner." colspan="4"/>
|
||||
<newline/>
|
||||
<field name="year"/>
|
||||
<newline/>
|
||||
<field name="limit_amount"/>
|
||||
<separator colspan="4"/>
|
||||
<group colspan="4">
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button colspan="1" name="get_partner" string="View Customers" type="object" icon="terp-partner"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_partner_vat_listing_13" model="ir.ui.view">
|
||||
<field name="name">Partner VAT Listing</field>
|
||||
<field name="model">partner.vat_13</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Partner VAT Listing">
|
||||
<label string="This wizard will create an XML file for VAT details and total invoiced amounts per partner." colspan="4"/>
|
||||
<newline/>
|
||||
<field name="year"/>
|
||||
<newline/>
|
||||
<field name="limit_amount"/>
|
||||
<separator colspan="4"/>
|
||||
<group colspan="4">
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button colspan="1" name="get_partner" string="View Customers" type="object" icon="terp-partner"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="action_partner_vat_listing_13" 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_13</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_partner_vat_listing_13"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record id="action_partner_vat_listing_13" 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_13</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_partner_vat_listing_13"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
<menuitem name="Annual Listing Of VAT-Subjected Customers" parent="l10n_be.menu_finance_belgian_statement" action="action_partner_vat_listing_13" id="l10n_be.partner_vat_listing"/>
|
||||
|
||||
<menuitem name="Annual Listing Of VAT-Subjected Customers" parent="l10n_be.menu_finance_belgian_statement" action="action_partner_vat_listing_13" id="l10n_be.partner_vat_listing"/>
|
||||
|
||||
<record id="view_vat_listing_13" model="ir.ui.view">
|
||||
<field name="name">Vat Listing</field>
|
||||
<field name="model">partner.vat.list_13</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Select Fiscal Year">
|
||||
<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"/>
|
||||
<separator colspan="4"/>
|
||||
<group colspan="4">
|
||||
<button colspan="2" name="create_xml" string="Create XML" type="object" icon="gtk-execute"/>
|
||||
<button colspan="2" name="print_vatlist" string="Print" type="object" icon="gtk-print"/>
|
||||
</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="Close" icon="gtk-cancel"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_vat_listing_13" model="ir.ui.view">
|
||||
<field name="name">Vat Listing</field>
|
||||
<field name="model">partner.vat.list_13</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<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>
|
||||
<separator colspan="4"/>
|
||||
<group colspan="4">
|
||||
<button colspan="2" name="create_xml" string="Create XML" type="object" icon="gtk-execute"/>
|
||||
<!-- Not fully implemented -->
|
||||
<!--button colspan="2" name="print_vatlist" string="Print" type="object" icon="gtk-print"/-->
|
||||
</group>
|
||||
<separator string="XML File has been Created." colspan="4"/>
|
||||
<field name="msg" colspan="4" nolabel="1"/>
|
||||
<field name="name"/>
|
||||
<field name="file_save"/>
|
||||
<separator colspan="4"/>
|
||||
<button special="cancel" string="Close" icon="gtk-cancel"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
</openerp>
|
||||
|
|
Loading…
Reference in New Issue