[ADD] l10n_be: convert account_vat_declaration wizard to osv_memory wizard
authorpsi (Open ERP) <psi@tinyerp.co.in>
Fri, 26 Mar 2010 14:13:52 +0000 (19:43 +0530)
committerpsi (Open ERP) <psi@tinyerp.co.in>
Fri, 26 Mar 2010 14:13:52 +0000 (19:43 +0530)
bzr revid: psi@tinyerp.co.in-20100326141352-bolnvlc15ky0um3p

addons/l10n_be/__terp__.py
addons/l10n_be/l10n_be_wizard.xml
addons/l10n_be/wizard/__init__.py
addons/l10n_be/wizard/account_vat_declaration.py [deleted file]
addons/l10n_be/wizard/l10n_be_account_vat_declaration.py [new file with mode: 0644]
addons/l10n_be/wizard/l10n_be_account_vat_declaration_view.xml [new file with mode: 0644]

index c6580e7..618367d 100644 (file)
@@ -50,6 +50,7 @@
     'update_xml': [
                 'account_pcmn_belgium.xml',
                 'l10n_be_wizard.xml',
+                'wizard/l10n_be_account_vat_declaration_view.xml',
                 'l10n_be_sequence.xml',
                 'fiscal_templates.xml',
                 'security/ir.model.access.csv'
index c20f1c6..86c4d82 100644 (file)
@@ -21,7 +21,7 @@
         type="wizard"
         id="partner_wizard_vat_menu"/>
 
-    <wizard
+<!--    <wizard
         string="Periodical VAT Declaration"
         name="wizard.account.xml.vat.declaration"
         menu="False"
@@ -32,7 +32,7 @@
         parent="menu_finance_belgian_statement"
         action="wizard_xml_vat_declaration"
         type="wizard"
-        id="account_wizard_vat_declaration"/>
+        id="account_wizard_vat_declaration"/> -->
 
        <wizard
         string="Partner VAT intra"
index 1050e8e..b811c54 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 ##############################################################################
-#    
+#
 #    OpenERP, Open Source Management Solution
 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 #
 #    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 account_vat_declaration
 import partner_vat_listing
 import wizard_vat_intra
+import l10n_be_account_vat_declaration
 
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/l10n_be/wizard/account_vat_declaration.py b/addons/l10n_be/wizard/account_vat_declaration.py
deleted file mode 100644 (file)
index 404b940..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-#    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
-#
-#    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU Affero General Public License as
-#    published by the Free Software Foundation, either version 3 of the
-#    License, or (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    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/>.
-#
-##############################################################################
-import time
-import datetime
-import base64
-
-import wizard
-import pooler
-from tools.translate import _
-
-form_fyear = """<?xml version="1.0"?>
-<form string="Select Period">
-    <field name="period" />
-</form>"""
-
-fields_fyear = {
-    'period': {'string': 'Period', 'type': 'many2one', 'relation': 'account.period', 'required': True,},
-}
-
-form = """<?xml version="1.0"?>
-<form string="Notification">
-     <separator string="XML Flie has been Created."  colspan="4"/>
-     <field name="msg" colspan="4" nolabel="1"/>
-     <field name="file_save" />
-</form>"""
-
-fields = {
-    'msg': {'string':'File created', 'type':'text', 'size':'100','readonly':True},
-    'file_save':{'string': 'Save File',
-        'type': 'binary',
-        'readonly': True,},
-}
-
-
-class wizard_vat_declaration(wizard.interface):
-
-    def _create_xml(self, cr, uid, data, context):
-        pool_obj = pooler.get_pool(cr.dbname)
-        obj_fyear = pool_obj.get('account.fiscalyear')
-        obj_tax_code = pool_obj.get('account.tax.code')
-        obj_user = pool_obj.get('res.users')
-        list_of_tags=['00','01','02','03','45','46','47','48','49','54','55','56','57','59','61','62','63','64','71','81','82','83','84','85','86','87','91']
-        obj_company = obj_user.browse(cr, uid, uid, context=context).company_id
-        user_cmpny = obj_company.name
-        vat_no=obj_company.partner_id.vat
-        if not vat_no:
-            raise wizard.except_wizard(_('Data Insufficient'),_('No VAT Number Associated with Main Company!'))
-
-        tax_code_ids = obj_tax_code.search(cr, uid, [], context=context)
-        ctx = context.copy()
-        ctx['period_id'] = data['form']['period'] #added context here
-        tax_info = obj_tax_code.read(cr, uid, tax_code_ids, ['code','sum_period'], context=ctx)
-
-        address = post_code = city = ''
-        if not obj_company.partner_id.address:
-            address = post_code = city = ''
-
-        city, post_code, address = pool_obj.get('res.company')._get_default_ad(obj_company.partner_id.address)
-
-
-        year_id = obj_fyear.find(cr, uid)
-
-        account_period = pool_obj.get('account.period').browse(cr, uid, data['form']['period'], context=context)
-        current_year = account_period.fiscalyear_id.name
-        period_code = account_period.code
-
-        send_ref = user_cmpny
-        if period_code:
-            send_ref = send_ref + period_code
-
-        data_of_file='<?xml version="1.0"?>\n<VATSENDING xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="MultiDeclarationTVA-NoSignature-14.xml">'
-        data_of_file +='\n\t<DECLARER>\n\t\t<VATNUMBER>'+str(vat_no)+'</VATNUMBER>\n\t\t<NAME>'+str(obj_company.name)+'</NAME>\n\t\t<ADDRESS>'+address+'</ADDRESS>'
-        data_of_file +='\n\t\t<POSTCODE>'+post_code+'</POSTCODE>\n\t\t<CITY>'+city+'</CITY>\n\t\t<SENDINGREFERENCE>'+send_ref+'</SENDINGREFERENCE>\n\t</DECLARER>'
-        data_of_file +='\n\t<VATRECORD>\n\t\t<RECNUM>1</RECNUM>\n\t\t<VATNUMBER>'+str(vat_no)+'</VATNUMBER>\n\t\t<DPERIODE>\n\t\t\t'
-
-        starting_month = account_period.date_start[5:7]
-        ending_month = account_period.date_stop[5:7]
-        if starting_month != ending_month:
-            #starting month and ending month of selected period are not the same
-            #it means that the accounting isn't based on periods of 1 month but on quarters
-            quarter = str(((int(starting_month) - 1) / 3) + 1)
-            data_of_file += '<QUARTER>'+quarter+'</QUARTER>\n\t\t\t'
-        else:
-            data_of_file += '<MONTH>'+starting_month+'</MONTH>\n\t\t\t'
-        data_of_file += '<YEAR>' + str(account_period.date_stop[:4]) + '</YEAR>\n\t\t</DPERIODE>\n\t\t<ASK RESTITUTION="NO" PAYMENT="NO"/>'
-        data_of_file +='\n\t\t<DATA>\n\t\t\t<DATA_ELEM>'
-
-        for item in tax_info:
-            if item['code']:
-                if item['code'] == '71-72':
-                    item['code']='71'
-                if item['code'] in list_of_tags:
-                    data_of_file +='\n\t\t\t\t<D'+str(int(item['code'])) +'>' + str(int(item['sum_period']*100)) +  '</D'+str(int(item['code'])) +'>'
-
-        data_of_file +='\n\t\t\t</DATA_ELEM>\n\t\t</DATA>\n\t</VATRECORD>\n</VATSENDING>'
-        data['form']['msg']='Save the File with '".xml"' extension.'
-        data['form']['file_save'] = base64.encodestring(data_of_file)
-        return data['form']
-
-    states = {
-        'init': {
-            'actions': [],
-            'result': {'type': 'form', 'arch': form_fyear, 'fields':fields_fyear, 'state':[('end', 'Cancel'),('go', 'Create XML')]},
-        },
-        'go': {
-            'actions': [_create_xml],
-            'result': {'type':'form', 'arch': form, 'fields': fields, 'state': [('end', 'Ok')]},
-        }
-    }
-
-wizard_vat_declaration('wizard.account.xml.vat.declaration')
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
diff --git a/addons/l10n_be/wizard/l10n_be_account_vat_declaration.py b/addons/l10n_be/wizard/l10n_be_account_vat_declaration.py
new file mode 100644 (file)
index 0000000..490709b
--- /dev/null
@@ -0,0 +1,112 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    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/>.
+#
+##############################################################################
+
+import time
+import datetime
+import base64
+from osv import osv, fields
+from tools.translate import _
+
+class l10n_be_vat_declaration(osv.osv_memory):
+    """ Vat Declaration """
+    _name = "l1on_be.vat.declaration"
+    _description = "Vat Declaration"
+
+    _columns = {
+        'period_id': fields.many2one('account.period','Period', required=True),
+        'msg': fields.text('File created', size=64, readonly=True),
+        'file_save' : fields.binary('Save File'),
+    }
+
+    _defaults = {
+        'msg': lambda *a:'''Save the File with '".xml"' extension.''',
+    }
+
+    def create_xml(self, cr, uid, ids, context={}):
+        obj_fyear = self.pool.get('account.fiscalyear')
+        obj_tax_code = self.pool.get('account.tax.code')
+        obj_acc_period = self.pool.get('account.period')
+        obj_user = self.pool.get('res.users')
+        obj_comp = self.pool.get('res.company')
+        obj_data = self.pool.get('ir.model.data')
+
+        list_of_tags=['00','01','02','03','45','46','47','48','49','54','55','56','57','59','61','62','63','64','71','81','82','83','84','85','86','87','91']
+        obj_company = obj_user.browse(cr, uid, uid, context=context).company_id
+        user_cmpny = obj_company.name
+        vat_no=obj_company.partner_id.vat
+        if not vat_no:
+            raise wizard.except_wizard(_('Data Insufficient'),_('No VAT Number Associated with Main Company!'))
+
+        tax_code_ids = obj_tax_code.search(cr, uid, [], context=context)
+        ctx = context.copy()
+        data  = self.read(cr, uid, ids)[0]
+        ctx['period_id'] = data['period_id'] #added context here
+        tax_info = obj_tax_code.read(cr, uid, tax_code_ids, ['code','sum_period'], context=ctx)
+
+        address = post_code = city = ''
+        if not obj_company.partner_id.address:
+            address = post_code = city = ''
+
+        city, post_code, address = obj_comp._get_default_ad(obj_company.partner_id.address)
+
+
+        year_id = obj_fyear.find(cr, uid)
+
+        account_period = obj_acc_period.browse(cr, uid, data['period_id'], context=context)
+        current_year = account_period.fiscalyear_id.name
+        period_code = account_period.code
+
+        send_ref = user_cmpny
+        if period_code:
+            send_ref = send_ref + period_code
+
+        data_of_file='<?xml version="1.0"?>\n<VATSENDING xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="MultiDeclarationTVA-NoSignature-14.xml">'
+        data_of_file +='\n\t<DECLARER>\n\t\t<VATNUMBER>'+str(vat_no)+'</VATNUMBER>\n\t\t<NAME>'+str(obj_company.name)+'</NAME>\n\t\t<ADDRESS>'+address+'</ADDRESS>'
+        data_of_file +='\n\t\t<POSTCODE>'+post_code+'</POSTCODE>\n\t\t<CITY>'+city+'</CITY>\n\t\t<SENDINGREFERENCE>'+send_ref+'</SENDINGREFERENCE>\n\t</DECLARER>'
+        data_of_file +='\n\t<VATRECORD>\n\t\t<RECNUM>1</RECNUM>\n\t\t<VATNUMBER>'+str(vat_no)+'</VATNUMBER>\n\t\t<DPERIODE>\n\t\t\t'
+
+        starting_month = account_period.date_start[5:7]
+        ending_month = account_period.date_stop[5:7]
+        if starting_month != ending_month:
+            #starting month and ending month of selected period are not the same
+            #it means that the accounting isn't based on periods of 1 month but on quarters
+            quarter = str(((int(starting_month) - 1) / 3) + 1)
+            data_of_file += '<QUARTER>'+quarter+'</QUARTER>\n\t\t\t'
+        else:
+            data_of_file += '<MONTH>'+starting_month+'</MONTH>\n\t\t\t'
+        data_of_file += '<YEAR>' + str(account_period.date_stop[:4]) + '</YEAR>\n\t\t</DPERIODE>\n\t\t<ASK RESTITUTION="NO" PAYMENT="NO"/>'
+        data_of_file +='\n\t\t<DATA>\n\t\t\t<DATA_ELEM>'
+
+        for item in tax_info:
+            if item['code']:
+                if item['code'] == '71-72':
+                    item['code']='71'
+                if item['code'] in list_of_tags:
+                    data_of_file +='\n\t\t\t\t<D'+str(int(item['code'])) +'>' + str(int(item['sum_period']*100)) +  '</D'+str(int(item['code'])) +'>'
+
+        data_of_file +='\n\t\t\t</DATA_ELEM>\n\t\t</DATA>\n\t</VATRECORD>\n</VATSENDING>'
+        data['file_save'] = base64.encodestring(data_of_file)
+        self.write(cr, uid, ids, {'file_save':data['file_save']}, context=context)
+
+
+l10n_be_vat_declaration()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
diff --git a/addons/l10n_be/wizard/l10n_be_account_vat_declaration_view.xml b/addons/l10n_be/wizard/l10n_be_account_vat_declaration_view.xml
new file mode 100644 (file)
index 0000000..f0c1919
--- /dev/null
@@ -0,0 +1,47 @@
+<?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_declaration" model="ir.ui.view">
+            <field name="name">Select Period</field>
+            <field name="model">l1on_be.vat.declaration</field>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+                       <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"/>
+                </group>
+                <separator string="XML Flie has been Created." 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_declaration" model="ir.actions.act_window">
+            <field name="name">Vat Declaraion</field>
+            <field name="type">ir.actions.act_window</field>
+            <field name="res_model">l1on_be.vat.declaration</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">form</field>
+            <field name="view_id" ref="view_vat_declaration"/>
+            <field name="target">new</field>
+       </record>
+
+           <menuitem
+               name="Periodical VAT Declaration"
+               parent="menu_finance_belgian_statement"
+               action="action_vat_declaration"
+               id="l10_be_vat_declaration"/>
+
+    </data>
+</openerp>
\ No newline at end of file