Meera Trambadia (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/6.0-opw-50926-mtr into 
lp:openobject-addons/6.0.

Requested reviews:
  Naresh(OpenERP) (nch-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-opw-50926-mtr/+merge/91251

l10n_be:-Improved the 'Partner VAT Intra' and 'Annual Listing of VAT-Subjected 
customers' wizards as per the new VAT format.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-opw-50926-mtr/+merge/91251
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/6.0-opw-50926-mtr.
=== modified file 'l10n_be/wizard/l10_be_partner_vat_listing.py'
--- l10n_be/wizard/l10_be_partner_vat_listing.py	2011-12-30 12:04:29 +0000
+++ l10n_be/wizard/l10_be_partner_vat_listing.py	2012-02-02 12:14:30 +0000
@@ -41,6 +41,7 @@
                     context, load='_classic_write')]
 
     def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
+        args.append(['id', 'in', context['partner_ids']])
         client = self.search(cr, uid, [('vat', '=', name)]+args, limit=limit, context=context)
         if not client:
             client = self.search(cr, uid, [('name', 'ilike', '%%%s%%' % name)]+args, limit=limit, context=context)
@@ -58,12 +59,14 @@
         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]
-        
-        domains = [('date_start','>=',data['date_start']),('date_stop','<=',data['date_stop'])]
-        period = obj_period.search(cursor, user, domains, context=context)
+
+        year = data['year']
+        date_start = year + '-01-01'
+        date_stop = year + '-12-31'
+        period = obj_period.search(cursor, user, [('date_start' ,'>=', date_start), ('date_stop','<=',date_stop)])
         if not period:
-            raise osv.except_osv(_('Warning !'), _('Please select the proper Start date and End Date'))
-        
+             raise osv.except_osv(_('Data Insufficient!'), _('No data for the selected Year.'))
+
         p_id_list = obj_partner.search(cursor, user, [('vat_subjected', '!=', False)], context=context)
         if not p_id_list:
              raise osv.except_osv(_('Data Insufficient!'), _('No partner has a VAT Number asociated with him.'))
@@ -77,7 +80,7 @@
             #(or one of their) default address(es) located in Belgium.
             go_ahead = False
             for ads in obj_partner.address:
-                if ads.type == 'default' and (ads.country_id and ads.country_id.code == 'BE'):
+                if ads.type == 'default' and (ads.country_id and ads.country_id.code == 'BE') and (obj_partner.vat or '').startswith('BE'):
                     go_ahead = True
                     break
             if not go_ahead:
@@ -87,7 +90,7 @@
             if not line_info:
                 continue
 
-            record['vat'] = obj_partner.vat
+            record['vat'] = obj_partner.vat.replace(' ','').upper()
 
             #it seems that this listing is only for belgian customers
             record['country'] = 'BE'
@@ -96,14 +99,14 @@
             record['turnover'] = 0
             record['name'] = obj_partner.name
             for item in line_info:
-                if item[0] == 'produit':
+                if item[0] in ('income','produit'):
                     record['turnover'] += item[1]
                 else:
                     record['amount'] += item[1]
             id_client = obj_vat_lclient.create(cursor, user, record, context=context)
             partners.append(id_client)
             records.append(record)
-        context.update({'partner_ids': partners, 'date_start': data['date_start'], 'date_stop': data['date_stop'], 'limit_amount': data['limit_amount'], 'mand_id':data['mand_id']})
+        context.update({'partner_ids': partners, 'year': data['year'], 'limit_amount': data['limit_amount']})
         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 {
@@ -118,16 +121,13 @@
             }
 
     _columns = {
-        'date_start': fields.date('Start of Period', required=True),
-        'date_stop': fields.date('End of Period', 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"),
+        'year': fields.char('Year', size=4, required=True),
         'limit_amount': fields.integer('Limit Amount', required=True),
-        'test_xml': fields.boolean('Test XML file', help="Sets the XML output as test file"),
         }
-    
+
     _defaults = {
-        'date_start': lambda *a: time.strftime('%Y-01-01'),
-        'date_stop': lambda *a: time.strftime('%Y-12-01'),
+        'year': lambda *a: str(int(time.strftime('%Y'))-1),
+        'limit_amount': 250,
         }
 partner_vat()
 
@@ -140,13 +140,17 @@
         '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={
-        'partner_ids': _get_partners
+        'partner_ids': _get_partners,
+        'identification_type' : 'tin',
             }
 
     def create_xml(self, cursor, user, ids, context=None):
@@ -165,38 +169,83 @@
         if not company_vat:
             raise osv.except_osv(_('Data Insufficient'),_('No VAT Number Associated with Main Company!'))
 
-        cref = company_vat + seq_controlref
+        company_vat = company_vat.replace(' ','').upper()
+        SenderId = company_vat[2:]
+        issued_by = company_vat[:2]
+        cref = SenderId + seq_controlref
         dnum = cref + seq_declarantnum
-        date_stop = context.get('date_stop')
-        
-        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"; xsi:schemaLocation="http://www.minfin.fgov.be/VatList VatList.xml" RecipientId="VAT-ADMIN" SenderId="'+ str(company_vat) + '"'
-        data_file +=' ControlRef="'+ cref + '" MandataireId="'+ 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>'+ 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>'+ date_stop[:4] +'</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])
@@ -209,7 +258,18 @@
         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']:
@@ -218,24 +278,36 @@
             sum_tax += line['amount']
             sum_turnover += line['turnover']
 
-            if not line['vat']:
-                raise osv.except_osv(_('Warning !'), _("Missing VAT ,Partner %s does not have a vat number") % line['name'])
-            if not line['country']:
-                raise osv.except_osv(_('Warning !'), _("Missing Country ,Partner %s does not have a country") % line['name'])
-            data_clientinfo = "".join([
-                data_clientinfo,
-                '<ClientList SequenceNum="',str(seq),'">\n',
-                '\t<CompanyInfo>\n',
-                '\t\t<VATNum>',line['vat'],'</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>\n'
-            ])
-            
-        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</VatList>'
+            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_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_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_clientinfo + 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)

=== modified file 'l10n_be/wizard/l10n_be_partner_vat_listing.xml'
--- l10n_be/wizard/l10n_be_partner_vat_listing.xml	2012-01-17 13:12:24 +0000
+++ l10n_be/wizard/l10n_be_partner_vat_listing.xml	2012-02-02 12:14:30 +0000
@@ -7,30 +7,25 @@
 	        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="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="date_start" default_focus="1"/>
-				    <newline/>
-				    <field name="date_stop"/>
-				    <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"/>
+		<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="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"/>
+					<newline/>
+					<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"  icon="terp-partner"/>
-				    </group>
-			</form>
-            </field>
+					</group>
+				</form>
+			</field>
 		</record>
 
 		<record id="action_partner_vat_listing" model="ir.actions.act_window">
@@ -49,19 +44,29 @@
 	        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" default_focus="1"/>
-                	<separator colspan="4"/>
-                	<group colspan="4" >
-						<button colspan="1" name="create_xml" string="Create XML" type="object"  icon="gtk-execute"/>
-				    </group>
+		<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" >
+					<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="1" name="create_xml" string="Create XML" type="object"  icon="gtk-execute"/>
+	                </group>
 					<separator string="XML File has been Created." colspan="4"/>
 					<field name="msg" colspan="4" nolabel="1"/>
 					<field name="name"/>
@@ -69,9 +74,9 @@
 					<field name="file_save" />
 					<separator colspan="4"/>
 					<button special="cancel" string="Close" icon="gtk-cancel"/>
-                </form>
-            </field>
-        </record>
+				</form>
+			</field>
+		</record>
 
          <!-- osv_memory for vat listing of clients -->
 	     <record id="view_vat_listing_form" model="ir.ui.view">

=== modified file 'l10n_be/wizard/l10n_be_vat_intra.py'
--- l10n_be/wizard/l10n_be_vat_intra.py	2011-01-14 00:11:01 +0000
+++ l10n_be/wizard/l10n_be_vat_intra.py	2012-02-02 12:14:30 +0000
@@ -23,6 +23,7 @@
 
 from osv import osv, fields
 from tools.translate import _
+from report import report_sxw
 
 class partner_vat_intra(osv.osv_memory):
     """
@@ -51,55 +52,82 @@
     '''
     ),
         'period_ids': fields.many2many('account.period', 'account_period_rel', 'acc_id', 'period_id', 'Period (s)', help = 'Select here the period(s) you want to include in your intracom declaration'),
-        'tax_code_id': fields.many2one('account.tax.code', 'Tax Code', domain=[('parent_id', '=', False)]),
+        'tax_code_id': fields.many2one('account.tax.code', 'Tax Code', domain=[('parent_id', '=', False)], help="Keep empty to use the user's company"),
         '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"),
         'msg': fields.text('File created', size=14, readonly=True),
         'no_vat': fields.text('Partner With No VAT', size=14, readonly=True, help="The Partner whose VAT number is not defined they doesn't include in XML File."),
         'file_save' : fields.binary('Save File', readonly=True),
         'country_ids': fields.many2many('res.country', 'vat_country_rel', 'vat_id', 'country_id', 'European Countries'),
+        'comments': fields.text('Comments'),
+        'identification_type': fields.selection([('tin','TIN'), ('nvat','NVAT'), ('other','Other')], 'Identification Type', required=True),
+        'other': fields.char('Other Qlf', size=16, help="Description of Identification Type"),
         }
 
     _defaults = {
         'country_ids': _get_europe_country,
         'file_save': _get_xml_data,
         'name': 'vat_Intra.xml',
+        'identification_type': 'tin',
     }
 
-    def create_xml(self, cursor, user, ids, context=None):
+    def _get_datas(self, cr, uid, ids, context=None):
+        """Collects require data for vat intra xml
+        :param ids: id of wizard.
+        :return: dict of all data to be used to generate xml for Partner VAT Intra.
+        :rtype: dict
+        """
+        if context is None:
+            context = {}
+
         obj_user = self.pool.get('res.users')
         obj_sequence = self.pool.get('ir.sequence')
         obj_partner = self.pool.get('res.partner')
         obj_partner_add = self.pool.get('res.partner.address')
-        mod_obj = self.pool.get('ir.model.data')
-        street = zip_city = country = p_list = data_clientinfo = ''
+
+        xmldict = {}
+        post_code = street = city = country = p_list = data_clientinfo = ''
         seq = amount_sum = 0
 
-        if context is None:
-            context = {}
-        data_tax = self.browse(cursor, user, ids[0], context=context)
-        if data_tax.tax_code_id:
-            data_cmpny = data_tax.tax_code_id.company_id
+        wiz_data = self.browse(cr, uid, ids[0], context=context)
+        type = wiz_data.identification_type or ''
+        other = wiz_data.other or ''
+        comments = wiz_data.comments
+
+        if wiz_data.tax_code_id:
+            data_cmpny = wiz_data.tax_code_id.company_id
         else:
-            data_cmpny = obj_user.browse(cursor, user, user).company_id
-        data  = self.read(cursor, user, ids)[0]
+            data_cmpny = obj_user.browse(cr, uid, uid, context=context).company_id
+
+        # Get Company vat
         company_vat = data_cmpny.partner_id.vat
         if not company_vat:
             raise osv.except_osv(_('Data Insufficient'),_('No VAT Number Associated with Main Company!'))
-
-        seq_controlref = obj_sequence.get(cursor, user, 'controlref')
-        seq_declarantnum = obj_sequence.get(cursor, user, 'declarantnum')
+        company_vat = company_vat.replace(' ','').upper()
+        issued_by = company_vat[:2]
+
+        if len(wiz_data.period_code) != 6:
+            raise osv.except_osv(_('Wrong Period Code'), _('The period code you entered is not valid.'))
+
+        if not wiz_data.period_ids:
+            raise osv.except_osv(_('Data Insufficient!'),_('Please select at least one Period.'))
+
+        p_id_list = obj_partner.search(cr, uid, [('vat','!=',False)], context=context)
+        if not p_id_list:
+            raise osv.except_osv(_('Data Insufficient!'),_('No partner has a VAT Number asociated with him.'))
+
+        seq_controlref = obj_sequence.get(cr, uid, 'controlref')
+        seq_declarantnum = obj_sequence.get(cr, uid, 'declarantnum')
         cref = company_vat[2:] + seq_controlref[-4:]
         dnum = cref + seq_declarantnum[-5:]
-        if len(data['period_code']) != 6:
-            raise osv.except_osv(_('Wrong Period Code'), _('The period code you entered is not valid.'))
 
-        addr = obj_partner.address_get(cursor, user, [data_cmpny.partner_id.id], ['invoice'])
+        addr = obj_partner.address_get(cr, uid, [data_cmpny.partner_id.id], ['invoice'])
+        email = data_cmpny.partner_id.email or ''
+        phone = data_cmpny.partner_id.phone or ''
         if addr.get('invoice',False):
-            ads = obj_partner_add.browse(cursor, user, [addr['invoice']])[0]
-            zip_city = (ads.city or '') + ' ' + (ads.zip or '')
-            if zip_city== ' ':
-                zip_city = ''
+            ads = obj_partner_add.browse(cr, uid, [addr['invoice']])[0]
+            city = (ads.city or '')
+            post_code = (ads.zip or '')
             if ads.street:
                 street = ads.street
             if ads.street2:
@@ -108,44 +136,116 @@
             if ads.country_id:
                 country = ads.country_id.code
 
-        comp_name = data_cmpny.name
-        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['mand_id'] + '" SenderDate="'+ str(sender_date)+ '"'
-        data_file += ' VersionTech="1.3">'
-        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>'+ comp_name +'</Name>\n\t\t\t<Street>'+ street +'</Street>\n\t\t\t<CityAndZipCode>'+ zip_city +'</CityAndZipCode>'
-        data_file += '\n\t\t\t<Country>' + country +'</Country>\n\t\t</CompanyInfo>\n\t</AgentRepr>'
-        data_comp = '\n\t\t<CompanyInfo>\n\t\t\t<VATNum>'+str(company_vat[2:])+'</VATNum>\n\t\t\t<Name>'+ comp_name +'</Name>\n\t\t\t<Street>'+ street +'</Street>\n\t\t\t<CityAndZipCode>'+ zip_city +'</CityAndZipCode>\n\t\t\t<Country>'+ country +'</Country>\n\t\t</CompanyInfo>'
-        data_period = '\n\t\t<Period>'+ data['period_code'] +'</Period>' #trimester
-        p_id_list = obj_partner.search(cursor, user, [('vat','!=',False)])
-        if not p_id_list:
-            raise osv.except_osv(_('Data Insufficient!'),_('No partner has a VAT Number asociated with him.'))
+        xmldict.update({
+                        'company_name': data_cmpny.name,
+                        'company_vat': company_vat,
+                        'vatnum':  company_vat[2:],
+                        'controlref': seq_controlref,
+                        'cref': cref,
+                        'mand_id': wiz_data.mand_id,
+                        'sender_date': str(time.strftime('%Y-%m-%d')),
+                        'street': street,
+                        'city': city,
+                        'post_code': post_code,
+                        'country': country,
+                        'email': email,
+                        'phone': phone,
+                        'period': wiz_data.period_code,
+                        'clientlist': [],
+                        'comments': comments,
+                        'type': type.upper(),
+                        'other': other,
+                        'issued_by': issued_by,
+                        })
 
-        if not data['period_ids']:
-            raise osv.except_osv(_('Data Insufficient!'),_('Please select at least one Period.'))
-        cursor.execute('''SELECT p.name As partner_name, l.partner_id AS partner_id, p.vat AS vat, t.code AS intra_code, SUM(l.tax_amount) AS amount
+        codes = ('44', '46L', '46T')
+        cr.execute('''SELECT p.name As partner_name, l.partner_id AS partner_id, p.vat AS vat, t.code AS intra_code, SUM(l.tax_amount) AS amount
                       FROM account_move_line l
                       LEFT JOIN account_tax_code t ON (l.tax_code_id = t.id)
                       LEFT JOIN res_partner p ON (l.partner_id = p.id)
-                      WHERE t.code IN ('44a','44b','88')
+                      WHERE t.code IN %s
                        AND l.period_id IN %s
-                      GROUP BY p.name, l.partner_id, p.vat, t.code''', (tuple(data['period_ids']), ))
-        for row in cursor.dictfetchall():
+                      GROUP BY p.name, l.partner_id, p.vat, t.code''', (codes, tuple([p.id for p in wiz_data.period_ids])))
+
+        p_count = 0
+        for row in cr.dictfetchall():
             if not row['vat']:
                 p_list += str(row['partner_name']) + ', '
+                p_count += 1
                 continue
+
             seq += 1
             amt = row['amount'] or 0
             amt = int(round(amt * 100))
             amount_sum += amt
-            intra_code = row['intra_code'] == '88' and 'L' or (row['intra_code'] == '44b' and 'T' or (row['intra_code'] == '44a' and 'S' or ''))
-            data_clientinfo +='\n\t\t<ClientList SequenceNum="'+str(seq)+'">\n\t\t\t<CompanyInfo>\n\t\t\t\t<VATNum>'+row['vat'][2:] +'</VATNum>\n\t\t\t\t<Country>'+row['vat'][:2] +'</Country>\n\t\t\t</CompanyInfo>\n\t\t\t<Amount>'+str(amt) +'</Amount>\n\t\t\t<Code>'+str(intra_code) +'</Code>\n\t\t</ClientList>'
-        amount_sum = int(amount_sum)
-        data_decl = '\n\t<DeclarantList SequenceNum="1" DeclarantNum="'+ dnum + '" ClientNbr="'+ str(seq) +'" AmountSum="'+ str(amount_sum) +'" >'
-        data_file += data_decl + data_comp + str(data_period) + data_clientinfo + '\n\t</DeclarantList>\n</VatIntra>'
+
+            intra_code = row['intra_code'] == '44' and 'S' or (row['intra_code'] == '46L' and 'L' or (row['intra_code'] == '46T' and 'T' or ''))
+#            intra_code = row['intra_code'] == '88' and 'L' or (row['intra_code'] == '44b' and 'T' or (row['intra_code'] == '44a' and 'S' or ''))
+
+            xmldict['clientlist'].append({
+                                        'partner_name': row['partner_name'],
+                                        'seq': seq,
+                                        'vatnum': row['vat'][2:].replace(' ','').upper(),
+                                        'vat': row['vat'],
+                                        'country': row['vat'][:2],
+                                        'amount': amt,
+                                        'intra_code': row['intra_code'],
+                                        'code': intra_code})
+
+        xmldict.update({'dnum': dnum, 'clientnbr': str(seq), 'amountsum': amount_sum, 'partner_wo_vat': p_count})
+        return xmldict
+
+    def create_xml(self, cursor, user, ids, context=None):
+        """Creates xml that is to be exported and sent to estate for partner vat intra.
+        :return: Value for next action.
+        :rtype: dict
+        """
+        mod_obj = self.pool.get('ir.model.data')
+        xml_data = self._get_datas(cursor, user, ids, context=context)
+        month_quarter = xml_data['period'][:2]
+        year = xml_data['period'][2:]
+        data_file = ''
+        for country in xml_data['clientlist']:
+            if country['country'] == 'BE':
+                country['country'] = ''
+            else:
+                country['country'] = country['country']
+
+        # Can't we do this by etree?
+        data_head = """<?xml version="1.0"?>
+<IntraConsignment xmlns="http://www.minfin.fgov.be/IntraConsignment"; IntraListingsNbr="1">
+    <Representative>
+        <RepresentativeID identificationType="%(type)s" issuedBy="%(issued_by)s" otherQlf="%(other)s">%(company_vat)s</RepresentativeID>
+        <Name>%(company_name)s</Name>
+        <Street>%(street)s</Street>
+        <PostCode>%(post_code)s</PostCode>
+        <City>%(city)s</City>
+        <CountryCode>%(country)s</CountryCode>
+        <EmailAddress>%(email)s</EmailAddress>
+        <Phone>%(phone)s</Phone>
+    </Representative>
+    <RepresentativeReference>%(mand_id)s</RepresentativeReference>""" % (xml_data)
+
+        data_comp_period = '\n\t\t<ReplacedIntraListing></ReplacedIntraListing>\n\t\t<Declarant>\n\t\t\t<VATNumber xmlns="http://www.minfin.fgov.be/InputCommon";>%(vatnum)s</VATNumber>\n\t\t\t<Name>%(company_name)s</Name>\n\t\t\t<Street>%(street)s</Street>\n\t\t\t<PostCode>%(post_code)s</PostCode>\n\t\t\t<City>%(city)s</City>\n\t\t\t<CountryCode>%(country)s</CountryCode>\n\t\t\t<EmailAddress>%(email)s</EmailAddress>\n\t\t\t<Phone>%(phone)s</Phone>\n\t\t</Declarant>' % (xml_data)
+        if month_quarter.startswith('3'):
+            data_comp_period += '\n\t\t<Period>\n\t\t\t<Quarter>'+month_quarter+'</Quarter> \n\t\t\t<Year>'+year+'</Year>\n\t\t</Period>'
+        elif month_quarter.startswith('0') and month_quarter.endswith('0'):
+            data_comp_period+= '\n\t\t<Period>%(period)s</Period>' % (xml_data)
+        else:
+            data_comp_period += '\n\t\t<Period>\n\t\t\t<Month>'+month_quarter+'</Month> \n\t\t\t<Year>'+year+'</Year>\n\t\t</Period>'
+
+        data_clientinfo = ''
+        for client in xml_data['clientlist']:
+            data_clientinfo +='\n\t\t<IntraClient SequenceNumber="%(seq)s">\n\t\t\t<CompanyVATNumber issuedBy="%(country)s">%(vatnum)s</CompanyVATNumber>\n\t\t\t<Code>%(code)s</Code>\n\t\t\t<Amount>%(amount)s</Amount>\n\t\t\t<CorrectingPeriod>\n\t\t\t\t<Month></Month> \n\t\t\t\t<Year></Year>\n\t\t\t</CorrectingPeriod>\n\t\t</IntraClient>' % (client)
+
+        data_decl = '\n\t<IntraListing SequenceNumber="1" ClientsNbr="%(clientnbr)s" DeclarantReference="%(dnum)s" AmountSum="%(amountsum)s">' % (xml_data)
+
+        data_file += data_head + data_decl + data_comp_period + data_clientinfo + '\n\t\t<FileAttachment></FileAttachment> \n\t\t<Comment>%(comments)s</Comment>\n\t</IntraListing>\n</IntraConsignment>' % (xml_data)
+        context['file_save'] = data_file
+
         model_data_ids = mod_obj.search(cursor, user,[('model','=','ir.ui.view'),('name','=','view_vat_intra_save')], context=context)
         resource_id = mod_obj.read(cursor, user, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
-        context['file_save'] = data_file
+
         return {
             'name': _('Save'),
             'context': context,
@@ -158,6 +258,28 @@
             'target': 'new',
         }
 
+    def preview(self, cr, uid, ids, context=None):
+        xml_data = self._get_datas(cr, uid, ids, context=context)
+        datas = {
+             'ids': [],
+             'model': 'partner.vat.intra',
+             'form': xml_data
+        }
+        return {
+            'type': 'ir.actions.report.xml',
+            'report_name': 'partner.vat.intra.print',
+            'datas': datas,
+        }
+
 partner_vat_intra()
 
+class vat_intra_print(report_sxw.rml_parse):
+    def __init__(self, cr, uid, name, context):
+        super(vat_intra_print, self).__init__(cr, uid, name, context=context)
+        self.localcontext.update({
+            'time': time,
+        })
+
+report_sxw.report_sxw('report.partner.vat.intra.print', 'partner.vat.intra', 'addons/l10n_be/wizard/l10n_be_vat_intra_print.rml', parser=vat_intra_print)
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added file 'l10n_be/wizard/l10n_be_vat_intra_print.rml'
--- l10n_be/wizard/l10n_be_vat_intra_print.rml	1970-01-01 00:00:00 +0000
+++ l10n_be/wizard/l10n_be_vat_intra_print.rml	2012-02-02 12:14:30 +0000
@@ -0,0 +1,141 @@
+<?xml version="1.0"?>
+<document filename="Partner VAT Intra.pdf">
+  <template pageSize="(595.0,842.0)" title="Partner VAT Intra" author="OpenERP S.A.([email protected])" allowSplitting="20">
+    <pageTemplate id="first">
+      <frame id="first" x1="34.0" y1="28.0" width="530" height="786"/>
+    </pageTemplate>
+  </template>
+  <stylesheet>
+    <blockTableStyle id="Table_General_Header">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="0,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="-1,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,1"/>
+      <lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="0,0" stop="-1,1"/>
+    </blockTableStyle>
+    <blockTableStyle id="table_content_header">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,1"/>
+    </blockTableStyle>
+    <blockTableStyle id="table_content_details">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="-1,-1"/>
+    </blockTableStyle>
+    <blockTableStyle id="table_total">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEABOVE" colorName="#000000" start="-2,0" stop="-1,0"/>
+    </blockTableStyle>
+    <initialize>
+      <paraStyle name="all" alignment="justify"/>
+    </initialize>
+
+    <paraStyle name="terp_header" fontName="Helvetica-Bold" fontSize="15.0" leading="15" alignment="CENTER" />
+    <paraStyle name="terp_tblheader_General" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_tblheader_General_Right" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_default_9" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Centre_9" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="9.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Right_9" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="9.0" leading="11" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_2" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="2.0" leading="3" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <images/>
+  </stylesheet>
+  <story>
+    <para style="terp_header">Partner VAT Intra</para>
+    <para style="terp_default_9">
+      <font color="white"> </font>
+    </para>
+    <para style="terp_default_9">
+      <font color="white"> </font>
+    </para>
+    <blockTable colWidths="175,175,175" style="Table_General_Header">
+      <tr>
+        <td>
+          <para style="terp_tblheader_General_Centre">Company Name</para>
+        </td>
+        <td>
+          <para style="terp_tblheader_General_Centre">VAT Number</para>
+        </td>
+        <td>
+          <para style="terp_tblheader_General_Centre">Partners without VAT</para>
+        </td>
+      </tr>
+      <tr>
+        <td>
+          <para style="terp_default_Centre_9">[[ data['form']['company_name'] ]]</para>
+        </td>
+        <td>
+          <para style="terp_default_Centre_9">[[ data['form']['company_vat'] ]]</para>
+        </td>
+        <td>
+          <para style="terp_default_Centre_9">[[ data['form']['partner_wo_vat'] or '-']]</para>
+        </td>
+      </tr>
+    </blockTable>
+    <para style="terp_default_9">
+      <font color="white"> </font>
+    </para>
+    <blockTable colWidths="200.0,130,80,100.0" style="table_content_header">
+      <tr>
+        <td>
+          <para style="terp_tblheader_General">Partner Name</para>
+        </td>
+        <td>
+          <para style="terp_tblheader_General">Partner VAT</para>
+        </td>
+        <td>
+          <para style="terp_tblheader_General">Tax Code</para>
+        </td>
+        <td>
+          <para style="terp_tblheader_General_Right">Amount</para>
+        </td>
+      </tr>
+    </blockTable>
+    <section>
+      <para style="terp_default_2">[[ repeatIn(data['form']['clientlist'],'l') ]]</para>
+      <blockTable colWidths="200.0,130,80,100.0" style="table_content_details">
+        <tr>
+          <td>
+            <para style="terp_default_9">[[ l['partner_name'] ]]</para>
+          </td>
+          <td>
+            <para style="terp_default_9">[[ l['vat'] ]]</para>
+          </td>
+          <td>
+            <para style="terp_default_9">[[ l['intra_code'] ]]</para>
+          </td>
+          <td>
+            <para style="terp_default_Right_9">[[ l['amount']/100 ]] [[ company.currency_id.symbol ]]</para>
+          </td>
+        </tr>
+      </blockTable>
+    </section>
+    <blockTable colWidths="200.0,170,40,100.0" style="table_total">
+      <tr>
+        <td>
+          <para style="terp_default_9">
+            <font color="white"> </font>
+          </para>
+        </td>
+        <td>
+          <para style="terp_default_9">
+            <font color="white"> </font>
+          </para>
+        </td>
+        <td>
+          <para style="terp_tblheader_General_Right">Total:</para>
+        </td>
+        <td>
+          <para style="terp_tblheader_General_Right">[[ data['form']['amountsum']/100 ]] [[ company.currency_id.symbol ]]</para>
+        </td>
+      </tr>
+    </blockTable>
+    <para style="terp_default_2">
+      <font color="white"> </font>
+    </para>
+  </story>
+</document>
+

=== modified file 'l10n_be/wizard/l10n_be_vat_intra_view.xml'
--- l10n_be/wizard/l10n_be_vat_intra_view.xml	2011-01-14 00:11:01 +0000
+++ l10n_be/wizard/l10n_be_vat_intra_view.xml	2012-02-02 12:14:30 +0000
@@ -3,9 +3,9 @@
     <data>
 
     	<menuitem
-        id="menu_finance_belgian_statement"
-        name="Belgium Statements"
-        parent="account.menu_finance_legal_statement"/>
+	        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>
@@ -14,29 +14,37 @@
 			<field name="arch" type="xml">
 				<form string="Partner VAT intra">
 					<group width="450">
-						<separator string="Create an XML file for Vat Intra" colspan="4"/>
+                        <separator string="Create an XML file for Vat Intra" colspan="4"/>
 						<notebook colspan="4">
 							<page string="General Information">
 								<newline/>
 								<group>
-								<field name="period_code" colspan="4"/>
-								<newline/>
-								<field name="mand_id" colspan="4"/>
-								<newline/>
-								<field name="tax_code_id" string="Company" colspan="4" widget="selection"/>
-								<newline/>
+									<field name="period_code" colspan="4"/>
+									<newline/>
+									<field name="mand_id" colspan="4"/>
+									<newline/>
+									<field name="identification_type"/>
+									<newline/>
+									<field name="other" attrs="{'invisible':[('identification_type','!=','other')], 'required':[('identification_type','=','other')]}"/>
+									<newline/>
+									<field name="tax_code_id" string="Company" colspan="4" widget="selection"/>
+									<newline/>
 								</group>
 								<separator string="Periods" colspan="4"/>
 								<field name="period_ids" nolabel="1" colspan="4"/>
 								<newline/><label/>
-								</page>
-								<page string="European Countries">
-									<field name="country_ids" colspan="4" nolabel="1"/>
-								</page>
-								</notebook>
-								<separator colspan="4"/><label/>
-							<button special="cancel" string="Close" icon="gtk-cancel"/>
-							<button name="create_xml" string="Create XML" type="object" icon="gtk-execute"/>
+							</page>
+							<page string="Comments">
+                                <field name="comments" nolabel="1"/>
+							</page>
+							<page string="European Countries">
+                                <field name="country_ids" colspan="4" nolabel="1"/>
+							</page>
+						</notebook>
+						<separator colspan="4"/><label/>
+						<button special="cancel" string="Close" icon="gtk-cancel"/>
+						<button name="preview" string="_Preview" type="object" icon="gtk-print"/>
+						<button name="create_xml" string="Create XML" type="object" icon="gtk-execute"/>
 					</group>
 				</form>
 			</field>
@@ -48,17 +56,17 @@
 			<field name="type">form</field>
 			<field name="arch" type="xml">
 				<form string="Save XML">
-						<group width="450">
-							<separator colspan="2" string="Note: "/><newline/>
-							<label string="Save the File with '.xml' extension." colspan="2" align="0.0"/><newline/>
-							<field name="name" colspan="4"/>
-							<newline/>
-							<field name="file_save" colspan="4"/>
-							<newline/>
-							<separator string="Partner With No VAT" colspan="4"/>
-							<field nolabel="1" name="no_vat" colspan="4"/>
-							<separator colspan="4"/><label/>
-						<button special="cancel" string="Close" icon="gtk-cancel"/>
+					<group width="450">
+						<separator colspan="2" string="Note: "/><newline/>
+						<label string="Save the File with '.xml' extension." colspan="2" align="0.0"/><newline/>
+						<field name="name" colspan="4"/>
+						<newline/>
+						<field name="file_save" colspan="4"/>
+						<newline/>
+						<separator string="Partner With No VAT" colspan="4"/>
+						<field nolabel="1" name="no_vat" colspan="4"/>
+						<separator colspan="4"/><label/>
+                        <button special="cancel" string="Close" icon="gtk-cancel"/>
 					</group>
 				</form>
 			</field>

_______________________________________________
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

Reply via email to