Rucha (Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-partner-vat-intra-print-rpa into 
lp:openobject-addons.

Requested reviews:
  qdp (OpenERP) (qdp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-partner-vat-intra-print-rpa/+merge/84601

Added new button in Partner VAT Intra that calls a new rml report that contains 
details that are to be exported in xml, because currently there was not way to 
have a view of the data we are going to send by xml.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-partner-vat-intra-print-rpa/+merge/84601
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-partner-vat-intra-print-rpa.
=== modified file 'l10n_be/wizard/l10n_be_vat_intra.py'
--- l10n_be/wizard/l10n_be_vat_intra.py	2011-10-16 01:28:00 +0000
+++ l10n_be/wizard/l10n_be_vat_intra.py	2011-12-06 12:00:32 +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):
     """
@@ -66,38 +67,50 @@
         'name': 'vat_Intra.xml',
     }
 
-    def create_xml(self, cursor, user, ids, context=None):
+    def _get_datas(self, cr, uid, ids, context=None):
+        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')
+
+        xmldict = {}
         street = zip_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)
+
+        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!'))
         company_vat = company_vat.replace(' ','').upper()
 
-        seq_controlref = obj_sequence.get(cursor, user, 'controlref')
-        seq_declarantnum = obj_sequence.get(cursor, user, 'declarantnum')
+        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'])
         if addr.get('invoice',False):
-            ads = obj_partner_add.browse(cursor, user, [addr['invoice']])[0]
+            ads = obj_partner_add.browse(cr, uid, [addr['invoice']])[0]
             zip_city = (ads.city or '') + ' ' + (ads.zip or '')
             if zip_city== ' ':
                 zip_city = ''
@@ -109,46 +122,90 @@
             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.'))
-
-        if not data['period_ids']:
-            raise osv.except_osv(_('Data Insufficient!'),_('Please select at least one Period.'))
+        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,
+                        'zip_city': zip_city,
+                        'country': country,
+                        'period': wiz_data.period_code,
+                        'clientlist': []
+                        })
+        
         codes = ('44', '46L', '46T')
-        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
+        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 %s
                        AND l.period_id IN %s
-                      GROUP BY p.name, l.partner_id, p.vat, t.code''', (codes, 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'] == '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 ''))
-            data_clientinfo +='\n\t\t<ClientList SequenceNum="'+str(seq)+'">\n\t\t\t<CompanyInfo>\n\t\t\t\t<VATNum>'+row['vat'][2:].replace(' ','').upper() +'</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>'
+
+            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):
+        mod_obj = self.pool.get('ir.model.data')
+        xml_data = self._get_datas(cursor, user, ids, context=context)
+        data_file = ''
+
+        # Can't we do this by etree?
+        data_head = """<?xml version="1.0"?>
+<VatIntra xmlns="http://www.minfin.fgov.be/VatIntra"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; RecipientId="VAT-ADMIN" SenderId="%(company_vat)s" ControlRef="%(controlref)s" MandataireId="%(mand_id)s" SenderDate="%(sender_date)s" VersionTech="1.3">
+	<AgentRepr DecNumber="1">
+		<CompanyInfo>
+			<VATNum>%(company_vat)s</VATNum>
+			<Name>%(company_name)s</Name>
+			<Street>%(street)s</Street>
+			<CityAndZipCode>%(zip_city)s</CityAndZipCode>
+			<Country>%(country)s</Country>
+		</CompanyInfo>
+	</AgentRepr>""" % (xml_data)
+
+        data_comp_period = '\n\t\t<CompanyInfo>\n\t\t\t<VATNum>%(vatnum)s</VATNum>\n\t\t\t<Name>%(company_name)s</Name>\n\t\t\t<Street>%(street)s</Street>\n\t\t\t<CityAndZipCode>%(zip_city)s</CityAndZipCode>\n\t\t\t<Country>%(country)s</Country>\n\t\t</CompanyInfo>\n\t\t<Period>%(period)s</Period>' % (xml_data)
+
+        data_clientinfo = ''
+        for client in xml_data['clientlist']:
+            data_clientinfo +='\n\t\t<ClientList SequenceNum="%(seq)s">\n\t\t\t<CompanyInfo>\n\t\t\t\t<VATNum>%(vatnum)s</VATNum>\n\t\t\t\t<Country>%(country)s</Country>\n\t\t\t</CompanyInfo>\n\t\t\t<Amount>%(amount)s</Amount>\n\t\t\t<Code>%(code)s</Code>\n\t\t</ClientList>' % (client)
+
+        data_decl = '\n\t<DeclarantList SequenceNum="1" DeclarantNum="%(dnum)s" ClientNbr="%(clientnbr)s" AmountSum="%(amountsum)s" >' % (xml_data)
+
+        data_file += data_head + data_decl + data_comp_period + data_clientinfo + '\n\t</DeclarantList>\n</VatIntra>'
+        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,
@@ -161,6 +218,31 @@
             '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	2011-12-06 12:00:32 +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	2011-12-06 12:00:32 +0000
@@ -35,8 +35,9 @@
 								</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"/>
+							<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>

_______________________________________________
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