← Back to team overview

avanzosc team mailing list archive

[Merge] lp:~avanzosc/openerp-spain/6.0 into lp:openerp-spain/6.0

 

Oihane (Avanzosc) has proposed merging lp:~avanzosc/openerp-spain/6.0 into lp:openerp-spain/6.0.

Requested reviews:
  Pedro Manuel Baeza (pedro.baeza)

For more details, see:
https://code.launchpad.net/~avanzosc/openerp-spain/6.0/+merge/216883

Se ha cambiado el modulo para generar el modelo 340, ahora aquellas facturas que difieren en importe se marcan como erróneas permitiendo que se genere completamente el documento y luego pudiendo editar las facturas para corregir los errores.

Se han tenido en cuenta las sugerencias de PBaeza
-- 
https://code.launchpad.net/~avanzosc/openerp-spain/6.0/+merge/216883
Your team Avanzosc Developers is subscribed to branch lp:~avanzosc/openerp-spain/6.0.
=== modified file 'l10n_es_aeat_mod340/__openerp__.py'
--- l10n_es_aeat_mod340/__openerp__.py	2014-02-09 16:43:29 +0000
+++ l10n_es_aeat_mod340/__openerp__.py	2014-04-23 13:41:23 +0000
@@ -69,7 +69,8 @@
         'account_invoice_view.xml',
         'account_view.xml',
         'taxes_data.xml',
-        'taxes_data_pymes.xml'],
+        'taxes_data_pymes.xml',
+        'wizard/calculate_mod340_records_view.xml'],
     'installable' : True,
     'active' : False,
 }

=== modified file 'l10n_es_aeat_mod340/mod340.py'
--- l10n_es_aeat_mod340/mod340.py	2014-02-09 16:43:29 +0000
+++ l10n_es_aeat_mod340/mod340.py	2014-04-23 13:41:23 +0000
@@ -7,7 +7,7 @@
 #                       Ignacio Ibeas Izquierdo <ignacio@xxxxxxxxxx>
 #    Copyright (c) 2011 NaN Projectes de Programari Lliure, S.L.
 #                       http://www.NaN-tic.com
-#                   
+#
 #    $Id$
 #
 #    This program is free software: you can redistribute it and/or modify
@@ -25,7 +25,7 @@
 #
 ##############################################################################
 
-from osv import osv,fields
+from osv import osv, fields
 import time
 from datetime import datetime
 import netsvc
@@ -34,29 +34,27 @@
 from tools.translate import _
 import pooler
 
+
 class l10n_es_aeat_mod340(osv.osv):
-   
+
     def button_calculate(self, cr, uid, ids,  args, context=None):
-        
-        if not context:
+        if context is None:
             context = {}
 
         calculate_obj = self.pool.get('l10n.es.aeat.mod340.calculate_records')
-        calculate_obj._wkf_calculate_records(cr, uid, ids, context)   
-        
-        return True
-    
+
+        return calculate_obj._calculate_records(cr, uid, ids, context)
+
     def button_recalculate(self, cr, uid, ids, context=None):
         if context is None:
             context = {}
 
-        calculate_obj = self. pool.get('l10n.es.aeat.mod340.calculate_records')
-        calculate_obj._calculate_records(cr, uid, ids, context)
+        calculate_obj = self.pool.get('l10n.es.aeat.mod340.calculate_records')
 
-        return True
+        return calculate_obj._calculate_records(cr, uid, ids, context)
 
     def button_export(self, cr, uid, ids, context=None):
-        
+
         if context is None:
             context = {}
 
@@ -65,65 +63,96 @@
         export_obj._export_boe_file(cr, uid, ids, report)
 
         return True
-        
-    def _name_get(self, cr, uid, ids, field_name, arg, context={}):
+
+    def _name_get(self, cr, uid, ids, field_name, arg, context=None):
         """
         Returns the report name
         """
+        if context is None:
+            context = {}
+
         result = {}
         for report in self.browse(cr, uid, ids, context):
             result[report.id] = report.number
         return result
-    
-    def _get_number_records( self, cr, uid,ids, field_name, args,context ):
-        
-        result = {} 
+
+    def _get_number_records(self, cr, uid, ids, field_name, args, context):
+
+        result = {}
         for id in ids:
             result[id] = {}.fromkeys(
-               ['number_records','total_taxable','total_sharetax','total'],
-               0.0)
-    
-        for model in self.browse(cr, uid, ids,context):
+                ['number_records', 'total_taxable', 'total_sharetax', 'total'],
+                0.0)
+
+        for model in self.browse(cr, uid, ids, context):
 
             for issue in model.issued:
-                result[model.id]['number_records'] += len( issue.tax_line_ids )
-                result[model.id]['total_taxable'] +=issue.base_tax
-                result[model.id]['total_sharetax'] +=issue.amount_tax
-                result[model.id]['total'] +=issue.base_tax + issue.amount_tax
+                result[model.id]['number_records'] += len(issue.tax_line_ids)
+                result[model.id]['total_taxable'] += issue.base_tax
+                result[model.id]['total_sharetax'] += issue.amount_tax
+                result[model.id]['total'] += issue.base_tax + issue.amount_tax
 
             for issue in model.received:
-                result[model.id]['number_records'] += len( issue.tax_line_ids )
-                result[model.id]['total_taxable'] +=issue.base_tax
-                result[model.id]['total_sharetax'] +=issue.amount_tax
-                result[model.id]['total'] +=issue.base_tax + issue.amount_tax
+                result[model.id]['number_records'] += len(issue.tax_line_ids)
+                result[model.id]['total_taxable'] += issue.base_tax
+                result[model.id]['total_sharetax'] += issue.amount_tax
+                result[model.id]['total'] += issue.base_tax + issue.amount_tax
 
         return result
 
+    def _check_report_lines(self, cr, uid, ids, context=None):
+        """
+        Checks if all the report lines are correct
+        """
+        if context is None:
+            context = {}
+
+        for item in self.browse(cr, uid, ids, context):
+            ## Browse record lines to check if all are correct
+            for issued_record in item.issued:
+                if issued_record.warning:
+                    raise osv.except_osv(_('Error!'), _("There is at least a warning in one issued invoice."))
+
+            for received_record in item.received:
+                if received_record.warning:
+                    raise osv.except_osv(_('Error!'), _("There is at least a warning in one received invoice."))
+
+        return True
+
+    def _check_report(self, cr, uid, ids, context=None):
+        """
+        Checks if all the fields of the report are filled
+        """
+        if context is None:
+            context = {}
+
+        self._check_report_lines(cr, uid, ids, context=context)
+
     _inherit = "l10n.es.aeat.report"
     _name = 'l10n.es.aeat.mod340'
     _description = 'Model 340'
     _columns = {
-        'name': fields.function(_name_get, method=True, type="char", 
+        'name': fields.function(_name_get, method=True, type="char",
                                 size="64", string="Name"),
         'contact_phone': fields.char("Phone", size=9),
-        'phone_contact' : fields.char('Phone Contact',size=9),
-        'name_contact' : fields.char('Name And Surname Contact',size=40),
+        'phone_contact': fields.char('Phone Contact', size=9),
+        'name_contact': fields.char('Name And Surname Contact', size=40),
         'period_from': fields.many2one('account.period', 'Start period',
                                        states={'done': [('readonly', True)]}),
         'period_to': fields.many2one('account.period', 'End period',
                                      states={'done': [('readonly', True)]}),
-        'issued': fields.one2many('l10n.es.aeat.mod340.issued','mod340_id',
+        'issued': fields.one2many('l10n.es.aeat.mod340.issued', 'mod340_id',
                                   'Invoices Issued',
                                   states={'done': [('readonly', True)]}),
         'received': fields.one2many('l10n.es.aeat.mod340.received',
-                                    'mod340_id','Invoices Received',
+                                    'mod340_id', 'Invoices Received',
                                     states={'done': [('readonly', True)]}),
         'investment': fields.one2many('l10n.es.aeat.mod340.investment',
-                                      'mod340_id','Property Investment'),
+                                      'mod340_id', 'Property Investment'),
         'intracomunitarias': fields.one2many(
-                             'l10n.es.aeat.mod340.intracomunitarias',
-                             'mod340_id','Operations Intracomunitarias'),
-        
+                                'l10n.es.aeat.mod340.intracomunitarias',
+                                'mod340_id', 'Operations Intracomunitarias'),
+
         'ean13': fields.char('Electronic Code VAT reverse charge', size=16),
 
         'total_taxable':  fields.function(_get_number_records, method=True,
@@ -145,107 +174,109 @@
         'calculation_date': fields.date('Calculation date', readonly=True),
     }
     _defaults = {
-        'number' : lambda *a: '340',
-               }
+        'number': lambda *a: '340',
+    }
 
     def set_done(self, cr, uid, id, *args):
-        self.write(cr,uid,id,{'calculation_date': time.strftime('%Y-%m-%d'),
-                              'state': 'done',})
+        self.write(cr, uid, id,
+                   {'calculation_date': time.strftime('%Y-%m-%d'),
+                    'state': 'done'})
         wf_service = netsvc.LocalService("workflow")
         wf_service.trg_validate(uid, 'l10n.es.aeat.mod340', id, 'done', cr)
         return True
 
     def action_confirm(self, cr, uid, ids, context=None):
         """set to done the report and check its records"""
-        if context is None: context = {}
-
-        self.check_report(cr, uid, ids, context)
-        self.write(cr, uid, ids, {'state': 'done'})
-
-        return True
-
-    def confirm(self, cr, uid, ids, context=None):
-        """set to done the report and check its records"""
-
-        self.write(cr, uid, ids, {'state': 'done'})
-
-        return True
-
-    def cancel(self, cr, uid, ids, context=None):
-        """set to done the report and check its records"""
-
-        self.write(cr, uid, ids, {'state': 'canceled'})
-
-        return True
-    
+        if context is None:
+            context = {}
+
+        self._check_report(cr, uid, ids, context=context)
+        self.write(cr, uid, ids, {'state': 'done'})
+
+        return True
+
 l10n_es_aeat_mod340()
 
+
 class l10n_es_aeat_mod340_issued(osv.osv):
     _name = 'l10n.es.aeat.mod340.issued'
     _description = 'Invoices invoice'
-    _columns = {                        
-        'mod340_id': fields.many2one('l10n.es.aeat.mod340','Model 340',
-                                     ondelete="cascade"),
-        'partner_id':fields.many2one('res.partner','Partner',
-                                     ondelete="cascade"),
-        'partner_vat':fields.char('Company CIF/NIF',size=12),
+    _columns = {
+        'mod340_id': fields.many2one('l10n.es.aeat.mod340', 'Model 340',
+                                     ondelete="cascade"),
+        'partner_id': fields.many2one('res.partner', 'Partner',
+                                      ondelete="cascade"),
+        'partner_vat': fields.char('Company CIF/NIF', size=12),
         'representative_vat': fields.char('L.R. VAT number', size=9,
-                                      help="Legal Representative VAT number"),
+                                          help="Legal Representative VAT number"),
         'partner_country_code': fields.char('Country Code', size=2),
-        'invoice_id':fields.many2one('account.invoice','Invoice',
-                                     ondelete="cascade"),
-        'base_tax':fields.float('Base tax bill',digits=(13,2)),
-        'amount_tax':fields.float('Total tax',digits=(13,2)),
-        'total':fields.float('Total',digits=(13,2)),
+        'invoice_id': fields.many2one('account.invoice', 'Invoice',
+                                      ondelete="cascade"),
+        'base_tax': fields.float('Base tax bill', digits=(13, 2)),
+        'amount_tax': fields.float('Total tax', digits=(13, 2)),
+        'total': fields.float('Total', digits=(13, 2)),
         'tax_line_ids': fields.one2many('l10n.es.aeat.mod340.tax_line_issued',
                                         'invoice_record_id', 'Tax lines'),
         'date_invoice': fields.date('Date Invoice', readonly=True),
+        'warning': fields.boolean('Warning'),
+        'warn_message': fields.text('Warning message'),
     }
-    
+
     _order = 'date_invoice asc, invoice_id asc'
 l10n_es_aeat_mod340_issued()
 
+
 class l10n_es_aeat_mod340_received(osv.osv):
     _name = 'l10n.es.aeat.mod340.received'
     _description = 'Invoices Received'
     _inherit = 'l10n.es.aeat.mod340.issued'
     _columns = {
-        'tax_line_ids':fields.one2many('l10n.es.aeat.mod340.tax_line_received',
-                                       'invoice_record_id', 'Tax lines'),
+        'tax_line_ids': fields.one2many('l10n.es.aeat.mod340.tax_line_received',
+                                        'invoice_record_id', 'Tax lines'),
     }
 l10n_es_aeat_mod340_received()
 
+
 class l10n_es_aeat_mod340_investment(osv.osv):
     _name = 'l10n.es.aeat.mod340.investment'
     _description = 'Property Investment'
     _inherit = 'l10n.es.aeat.mod340.issued'
 l10n_es_aeat_mod340_investment()
 
+
 class l10n_es_aeat_mod340_intracomunitarias(osv.osv):
     _name = 'l10n.es.aeat.mod340.intracomunitarias'
     _description = 'Operations Intracomunitarias'
     _inherit = 'l10n.es.aeat.mod340.issued'
 l10n_es_aeat_mod340_intracomunitarias()
 
+
 class l10n_es_aeat_mod340_tax_line_issued(osv.osv):
     _name = 'l10n.es.aeat.mod340.tax_line_issued'
     _description = 'Mod340 vat lines issued'
     _columns = {
         'name': fields.char('Name', size=128, required=True, select=True),
-        'tax_percentage': fields.float('Tax percentage',digits=(0,2)),
-        'tax_amount': fields.float('Tax amount',digits=(13,2)),
-        'base_amount': fields.float('Base tax bill',digits=(13,2)),
+        'tax_percentage': fields.float('Tax percentage', digits=(0, 2)),
+        'tax_amount': fields.float('Tax amount', digits=(13, 2)),
+        'base_amount': fields.float('Base tax bill', digits=(13, 2)),
         'invoice_record_id': fields.many2one('l10n.es.aeat.mod340.issued',
-             'Invoice issued', required=True, ondelete="cascade", select=1),
+                                             'Invoice issued',
+                                             required=True,
+                                             ondelete="cascade",
+                                             select=1),
     }
 l10n_es_aeat_mod340_tax_line_issued()
 
+
 class l10n_es_aeat_mod340_tax_line_received(osv.osv):
     _name = 'l10n.es.aeat.mod340.tax_line_received'
     _description = 'Mod340 vat lines received'
     _inherit = 'l10n.es.aeat.mod340.tax_line_issued'
     _columns = {
         'invoice_record_id': fields.many2one('l10n.es.aeat.mod340.received',
-             'Invoice received', required=True, ondelete="cascade", select=1),
+                                             'Invoice received',
+                                             required=True,
+                                             ondelete="cascade",
+                                             select=1),
     }
 l10n_es_aeat_mod340_tax_line_received()

=== modified file 'l10n_es_aeat_mod340/mod340_view.xml'
--- l10n_es_aeat_mod340/mod340_view.xml	2014-02-09 16:43:29 +0000
+++ l10n_es_aeat_mod340/mod340_view.xml	2014-04-23 13:41:23 +0000
@@ -25,83 +25,81 @@
 		<field name="priority" eval="5"/>
 		<field name="arch" type="xml">
 		    <form string="Model 340">
-	                <group col="4" colspan="4">
-	                    	<field name="company_id" on_change="on_change_company_id(company_id)" required="1" select="1" readonly="1"/>
-	                        <field name="fiscalyear_id" select="1"/>
-	                    	<newline/>
-	                        <field name="period_from" select="1" required="1" domain="[('fiscalyear_id','=',fiscalyear_id)]"/>
-	                        <field name="period_to" select="1" required="1" domain="[('fiscalyear_id','=',fiscalyear_id)]"/>
-	                    	<newline />
-	                    	<field name="number"/>
-	                    	<field name="support_type"/>
-	                </group>
-	                <notebook colspan="4">
-	                    <page string="General">
-	                        <group string="Identification" colspan="4">
-	                            <field name="company_vat" required="1" />
-	                            <field name="phone_contact" />
-	                            <field name="name_contact" />
-	                            <field name="representative_vat" />
-	                        </group>
-	                        <group string="Susbtitutive/complementary declaration" colspan="4">
-	                            <field name="type"/>
-	                            <field name="previous_number"/>
-	                        </group>
-	                        <group string="Electronic Code VAT reverse charge" colspan="4">
-	                            <field name="ean13" nolabel="1"/>
-	                        </group>
-	                        <group string="Summary" colspan="4">
-	                    			<field name="number_records" select ="2" readonly="1"/>
-	                    			<newline/>
-	                    			<field name="total_taxable" select ="2" readonly="1"/>
-	                    			<field name="total_sharetax" select ="2" readonly="1"/>
-	                    			<field name="total" select="2" readonly="1"/>
-	                    			<newline/>
-	                    			<field name="calculation_date" select ="2" readonly="1"/>
-	                    		</group>
-	                    		<group colspan="4" col="10">                                
-				                   <button name="button_calculate"
-					                       type="object"
-					                       string="Calculate"
-					                       states="draft"	
-					                       icon="terp-stock_format-scientific"
-					                       />
-					               <button name="button_recalculate"
-					                       type="object"
-					                       string="Recalculate"
-					                       states="calculating,calculated"
-					                       icon="gtk-execute"/>
-					               <button name="button_export"
-					                       type="object"
-					                       string="Export to BOE"
-					                       states="done"
-					                       icon="gtk-execute"
-					                       />
-					               <button name="confirm" 
-					               		   string="Confirm" 
-					               		   type="object" 
-					               		   states="calculated" 
-					               		   icon="gtk-ok"/>
-					               <button name="cancel" 
-					                       string="Cancel" 
-					                       type="object" 
-					                       states="calculated,done" 
-					                       icon="gtk-cancel"/>
-					               <button name="action_recover" 
-					                       string="Draft" 
-					                       type="object" 
-					                       states="canceled" 
-					                       icon="gtk-undo"/>
-			                       <field name="state" />
-		                   	   </group>
-	                    </page>
-	                    <page string="Issued invoice" >
-	                        <field name="issued" nolabel="1" />
-	                    </page>
-	                    <page string="Received invoice" >
-	                        <field name="received" nolabel="1" /> 
-	                    </page>
-	                </notebook>
+				<group col="4" colspan="4">
+	            	<field name="company_id" on_change="on_change_company_id(company_id)" required="1" select="1" readonly="1"/>
+	                <field name="fiscalyear_id" select="1"/>
+	                <newline/>
+	                <field name="period_from" select="1" required="1" domain="[('fiscalyear_id','=',fiscalyear_id)]"/>
+	                <field name="period_to" select="1" required="1" domain="[('fiscalyear_id','=',fiscalyear_id)]"/>
+	                <newline />
+	                <field name="number"/>
+	                <field name="support_type"/>
+	            </group>
+                <notebook colspan="4">
+                    <page string="General">
+                        <group string="Identification" colspan="4">
+                            <field name="company_vat" required="1" />
+                            <field name="phone_contact" />
+                            <field name="name_contact" />
+                            <field name="representative_vat" />
+                        </group>
+                        <group string="Susbtitutive/complementary declaration" colspan="4">
+                            <field name="type"/>
+                            <field name="previous_number"/>
+                        </group>
+                        <group string="Electronic Code VAT reverse charge" colspan="4">
+                            <field name="ean13" nolabel="1"/>
+                        </group>
+                        <group string="Summary" colspan="4">
+                    			<field name="number_records" select ="2" readonly="1"/>
+                    			<newline/>
+                    			<field name="total_taxable" select ="2" readonly="1"/>
+                    			<field name="total_sharetax" select ="2" readonly="1"/>
+                    			<field name="total" select="2" readonly="1"/>
+                    			<newline/>
+                    			<field name="calculation_date" select ="2" readonly="1"/>
+                    		</group>
+                    		<group colspan="4" col="10">                                
+			                   <button name="button_calculate"
+				                       type="object"
+				                       string="Calculate"
+				                       states="draft"	
+				                       icon="terp-stock_format-scientific" />
+				               <button name="button_recalculate"
+				                       type="object"
+				                       string="Recalculate"
+				                       states="calculating,calculated"
+				                       icon="gtk-execute"/>
+				               <button name="button_export"
+				                       type="object"
+				                       string="Export to BOE"
+				                       states="done"
+				                       icon="gtk-execute" />
+							   <button name="confirm"
+							       	   string="Confirm" 
+							       	   type="workflow"
+							       	   states="calculated"
+							       	   icon="gtk-ok"/>
+				               <button name="cancel" 
+				                       string="Cancel" 
+				                       type="workflow" 
+				                       states="calculated,done" 
+				                       icon="gtk-cancel"/>
+				               <button name="action_recover" 
+				                       string="Draft" 
+				                       type="workflow" 
+				                       states="canceled" 
+				                       icon="gtk-undo"/>
+		                       <field name="state" />
+	                   	   </group>
+                    </page>
+                    <page string="Issued invoice" >
+                        <field name="issued" nolabel="1" />
+                    </page>
+                    <page string="Received invoice" >
+                        <field name="received" nolabel="1" /> 
+                    </page>
+                </notebook>
              </form>
          </field>
 	</record>
@@ -109,13 +107,13 @@
 
 
     <!--Invoice Issued-->
-    
     <record id="view_l10n_es_aeat_mod340_invoice_issued_tree" model="ir.ui.view">
         <field name="name">l10n.es.aeat.mod340.issued.tree</field>
         <field name="model">l10n.es.aeat.mod340.issued</field>
         <field name="type">tree</field>
         <field name="arch" type="xml">
             <tree string="Issued invoices">
+                <field name="warning"/>
             	<field name="date_invoice"/>
                 <field name="partner_id"/>
                 <field name="partner_country_code"/>
@@ -145,8 +143,16 @@
                 <field name="amount_tax" />
                 <newline/>
                 <field name="total"/>
+                <field name="warning"/>
                 <newline />
-                <field name="tax_line_ids" />
+                <group colspan="2">
+	                <separator string="Tax lines" colspan="4"/>
+    	            <field name="tax_line_ids" nolabel="1" colspan="4"/>
+                </group>
+                <group attrs="{'invisible':[('warning','=',False)]}" colspan="2">
+                    <separator string="Warning Message" colspan="4"/>
+                	<field name="warn_message" nolabel="1" colspan="4" />
+                </group>
             </form>   
         </field>
     </record>
@@ -159,6 +165,7 @@
         <field name="type">tree</field>
         <field name="arch" type="xml">
             <tree string="Received invoices">
+                <field name="warning"/>
                 <field name="partner_id"/>
                 <field name="partner_country_code"/>
                 <field name="partner_vat"/>
@@ -187,8 +194,16 @@
                 <field name="amount_tax"/>
                 <newline/>
                 <field name="total"/>
+                <field name="warning"/>
                 <newline />
-                <field name="tax_line_ids" />
+                <group colspan="2">
+	                <separator string="Tax lines" colspan="4"/>
+    	            <field name="tax_line_ids" nolabel="1" colspan="4"/>
+                </group>
+                <group attrs="{'invisible':[('warning','=',False)]}" colspan="2">
+                    <separator string="Warning Message" colspan="4"/>
+                	<field name="warn_message" nolabel="1" colspan="4" />
+                </group>
             </form>   
         </field>
     </record>

=== modified file 'l10n_es_aeat_mod340/mod340_workflow.xml'
--- l10n_es_aeat_mod340/mod340_workflow.xml	2011-04-04 18:43:02 +0000
+++ l10n_es_aeat_mod340/mod340_workflow.xml	2014-04-23 13:41:23 +0000
@@ -4,7 +4,7 @@
 
         <record id="wkf_l10n_es_aeat_mod340_report" model="workflow">
             <field name="name">AEAT 340 Report</field>
-            <field name="osv">l10n.es.aeat.mod340.report</field>
+            <field name="osv">l10n.es.aeat.mod340</field>
             <field name="on_create">True</field>
         </record>
 
@@ -16,6 +16,8 @@
             <field name="wkf_id" ref="wkf_l10n_es_aeat_mod340_report"/>
             <field name="flow_start">True</field>
             <field name="name">draft</field>
+            <field name="action">write({'state':'draft'})</field>
+            <field name="kind">function</field>
         </record>
 
         <record id="act_calculate" model="workflow.activity">
@@ -35,7 +37,6 @@
         <record id="act_cancel" model="workflow.activity">
             <field name="wkf_id" ref="wkf_l10n_es_aeat_mod340_report"/>
             <field name="name">canceled</field>
-            <field name="flow_stop">True</field>
             <field name="action">write({'state':'canceled'})</field>
             <field name="kind">function</field>
         </record>
@@ -67,6 +68,12 @@
             <field name="act_to" ref="act_cancel"/>
             <field name="signal">cancel</field>
         </record>
+        
+        <record id="trans_cancel_draft" model="workflow.transition">
+            <field name="act_from" ref="act_cancel"/>
+            <field name="act_to" ref="act_draft"/>
+            <field name="signal">action_recover</field>
+        </record>
 
     </data>
 </openerp>

=== modified file 'l10n_es_aeat_mod340/wizard/calculate_mod340_records.py'
--- l10n_es_aeat_mod340/wizard/calculate_mod340_records.py	2014-02-14 17:37:59 +0000
+++ l10n_es_aeat_mod340/wizard/calculate_mod340_records.py	2014-04-23 13:41:23 +0000
@@ -29,133 +29,112 @@
 from datetime import datetime
 from dateutil.relativedelta import relativedelta
 
+
 class l10n_es_aeat_mod340_calculate_records(osv.osv_memory):
     _name = "l10n.es.aeat.mod340.calculate_records"
     _description = u"AEAT Model 340 Wizard - Calculate Records"
 
-    def _wkf_calculate_records(self, cr, uid, ids, context=None):
-        if context is None:
-            context = {}
-
-        self._calculate_records(cr, uid, ids, context, recalculate=False)
-        wf_service = netsvc.LocalService("workflow")
-        wf_service.trg_validate(uid, 'l10n.es.aeat.mod340', ids and ids[0],
-                                'calculate', cr)
-
-        
-
-    def _calculate_records(self, cr, uid, ids, context=None, recalculate=True):
+    def _calculate_records(self, cr, uid, ids, context=None):
         if context is None:
             context = {}
 
         try:
             report_obj = self.pool.get('l10n.es.aeat.mod340')
             mod340 = report_obj.browse(cr, uid, ids)[0]
-            
+
             invoices340 = self.pool.get('l10n.es.aeat.mod340.issued')
             invoices340_rec = self.pool.get('l10n.es.aeat.mod340.received')
             period_obj = self.pool.get('account.period')
-            
-            mod340.write({
-                'state' : 'calculated',
-                'calculation_date' : time.strftime('%Y-%m-%d %H:%M:%S')
-            })
-        
+
             if not mod340.company_id.partner_id.vat:
                 raise osv.except_osv(mod340.company_id.partner_id.name,
                                      _('This company dont have NIF'))
-        
-            wf_service = netsvc.LocalService("workflow")
-            wf_service.trg_validate(uid, 'l10n.es.aeat.mod347.report',
-                                    ids and ids[0], 'calculate', cr)
-
-            code = '340'+mod340.fiscalyear_id.code+''
-            code += mod340.period_to.date_stop[5:7]+'0001'
-            
+
+            code = '340' + mod340.fiscalyear_id.code + ''
+            code += mod340.period_to.date_stop[5:7] + '0001'
+
             account_period_ids = period_obj.build_ctx_periods(cr, uid,
-                                  mod340.period_from.id, mod340.period_to.id)
+                                                              mod340.period_from.id,
+                                                              mod340.period_to.id)
 
             if len(account_period_ids) == 0:
                 raise osv.except_osv(_('Error'),
-                   _("The periods selected don't belong to the fiscal year %s") 
-                   % (mod340.fiscalyear_id.name))
-            
+                                     _("The periods selected don't belong to the fiscal year %s")
+                                     % (mod340.fiscalyear_id.name))
+
             tot_base = 0
             tot_amount = 0
             tot_tot = 0
             tot_rec = 0
-            
-            
+
             #Limpieza de las facturas calculadas anteriormente
-            
-            del_ids = invoices340.search(cr, uid, [
-            ('mod340_id', '=', mod340.id)])
+            del_ids = invoices340.search(cr, uid, [('mod340_id', '=', mod340.id)])
 
             if del_ids:
                 invoices340.unlink(cr, uid, del_ids, context=context)
-                
-            del_ids = invoices340_rec.search(cr, uid, [
-            ('mod340_id', '=', mod340.id)])
+
+            del_ids = invoices340_rec.search(cr, uid, [('mod340_id', '=', mod340.id)])
 
             if del_ids:
                 invoices340_rec.unlink(cr, uid, del_ids, context=context)
-            
-            domain = [('period_id', 'in',account_period_ids), 
-                ('state', 'in', ('open', 'paid'))]
-            
-            invoice_obj=self.pool.get('account.invoice')
-            invoice_ids = invoice_obj.search(cr, uid,domain, context=context)
+
+            domain = [('period_id', 'in', account_period_ids),
+                      ('state', 'in', ('open', 'paid'))]
+
+            invoice_obj = self.pool.get('account.invoice')
+            invoice_ids = invoice_obj.search(cr, uid, domain, context=context)
+            warn_message = False
             for invoice in invoice_obj.browse(cr, uid, invoice_ids, context):
                 include = False
                 for tax_line in invoice.tax_line:
                     if tax_line.base_code_id and tax_line.base:
-                        if tax_line.base_code_id.mod340 == True:
+                        if tax_line.base_code_id.mod340:
                             include = True
-                if include == True:
+                if include:
                     if invoice.partner_id.vat_type == 1:
                         if not invoice.partner_id.vat:
                             raise osv.except_osv(
-                              _('La siguiente empresa no tiene asignado nif:'),
-                              invoice.partner_id.name)
-                    
+                                _('La siguiente empresa no tiene asignado nif:'),
+                                invoice.partner_id.name)
+
                     nif = invoice.partner_id.vat and re.match(r"([A-Z]{0,2})(.*)",
-                                          invoice.partner_id.vat).groups()[1]
+                                                              invoice.partner_id.vat).groups()[1]
                     country_code = invoice.address_invoice_id.country_id.code
-                    
+
                     values = {
                         'mod340_id': mod340.id,
-                        'partner_id':invoice.partner_id.id,
-                        'partner_vat':nif,
+                        'partner_id': invoice.partner_id.id,
+                        'partner_vat': nif,
                         'representative_vat': '',
-                        'partner_country_code' : country_code,
-                        'invoice_id':invoice.id,
-                        'base_tax':invoice.amount_untaxed,
-                        'amount_tax':invoice.amount_tax,
-                        'total':invoice.amount_total,
-                        'date_invoice':invoice.date_invoice,
+                        'partner_country_code': country_code,
+                        'invoice_id': invoice.id,
+                        'base_tax': invoice.amount_untaxed,
+                        'amount_tax': invoice.amount_tax,
+                        'total': invoice.amount_total,
+                        'date_invoice': invoice.date_invoice,
                     }
-                    if invoice.type in ( 'out_refund','in_refund'):
-                        values['base_tax'] *=-1
-                        values['amount_tax'] *=-1
-                        values['total'] *=-1
-    
-                    
-                    if invoice.type=="out_invoice" or invoice.type=="out_refund":
-                        invoice_created = invoices340.create(cr,uid,values)
-                        
-                    if invoice.type=="in_invoice" or invoice.type=="in_refund":
-                        invoice_created = invoices340_rec.create(cr,uid,values)
-                    
+                    if invoice.type in ('out_refund', 'in_refund'):
+                        values['base_tax'] *= -1
+                        values['amount_tax'] *= -1
+                        values['total'] *= -1
+
+                    if invoice.type in ('out_invoice', 'out_refund'):
+                        obj = invoices340
+                    else:
+                        obj = invoices340_rec
+
+                    invoice_created = obj.create(cr, uid, values)
+
                     tot_tax_invoice = 0
-                    check_tax=0
-                    check_base=0
-                    
+                    check_tax = 0
+                    check_base = 0
+
                     # Add the invoices detail to the partner record
                     for tax_line in invoice.tax_line:
                         if tax_line.base_code_id:
                             if tax_line.base_code_id and tax_line.base:
-                                tax_percentage = tax_line.amount/tax_line.base
-        
+                                tax_percentage = tax_line.amount / tax_line.base
+
                                 values = {
                                     'name': tax_line.name,
                                     'tax_percentage': tax_percentage,
@@ -163,63 +142,69 @@
                                     'base_amount': tax_line.base_amount,
                                     'invoice_record_id': invoice_created,
                                 }
-                                if invoice.type=="out_invoice" or invoice.type=="out_refund":
+                                if invoice.type in ("out_invoice", "out_refund"):
                                     issued_obj = self.pool.get('l10n.es.aeat.mod340.tax_line_issued')
                                     issued_obj.create(cr, uid, values)
-                                if invoice.type=="in_invoice" or invoice.type=="in_refund":
-                                    received_obj=self.pool.get('l10n.es.aeat.mod340.tax_line_received')
+                                if invoice.type in ("in_invoice", "in_refund"):
+                                    received_obj = self.pool.get('l10n.es.aeat.mod340.tax_line_received')
                                     received_obj.create(cr, uid, values)
                                 tot_tax_invoice += tax_line.tax_amount
                                 tot_rec += 1
                                 check_tax += tax_line.tax_amount
                                 if tax_percentage >= 0:
                                     check_base += tax_line.base_amount
-                                                            
+
+                                sign = 1
+                                if invoice.type in ('out_refund', 'in_refund'):
+                                    sign = -1
+
+                                warning = False
+                                error = ''
+                                if str(invoice.amount_untaxed * sign) != str(check_base):
+                                    warning = True
+                                    warn_message = True
+                                    error = _('Invoice  %s, Amount untaxed Lines %.2f do not correspond to AmountUntaxed on Invoice %.2f\n') % (invoice.number, check_base,  invoice.amount_untaxed*sign)
+
                     tot_base += invoice.amount_untaxed
                     tot_amount += tot_tax_invoice
                     tot_tot += invoice.amount_untaxed + tot_tax_invoice
-                
-                    if invoice.type=="out_invoice" or invoice.type=="out_refund":
-                        invoices340.write(cr,uid,invoice_created,
-                                          {'amount_tax':tot_tax_invoice})
-                    if invoice.type=="in_invoice" or invoice.type=="in_refund":
-                        invoices340_rec.write(cr,uid,invoice_created,
-                                              {'amount_tax':tot_tax_invoice})
-    
-                    sign=1
-                    if  invoice.type in ( 'out_refund','in_refund' ):
-                        sign = -1
-                        
-                    if str(invoice.amount_untaxed*sign) != str(check_base):
-                        raise osv.except_osv( "REVIEW INVOICE",
-                          _('Invoice  %s, Amount untaxed Lines %.2f do not correspond to AmountUntaxed on Invoice %.2f' )
-                          %(invoice.number, check_base,  invoice.amount_untaxed*sign)  )
-                
-            mod340.write({'total_taxable':tot_base,'total_sharetax':tot_amount,
-                      'number_records':tot_rec,'total':tot_tot,'number':code})
-            
-            if recalculate:
-                mod340.write({
-                    'state' : 'calculated',
-                    'calculation_date' : time.strftime('%Y-%m-%d %H:%M:%S')
-                })
-         
+
+                    obj.write(cr, uid, invoice_created,
+                              {'amount_tax': tot_tax_invoice,
+                               'warning': warning,
+                               'warn_message': error})
+
+            mod340.write({
+                'calculation_date': time.strftime('%Y-%m-%d %H:%M:%S'),
+                'number': code,
+            })
+
+            if mod340.state == 'draft':
+                wf_service = netsvc.LocalService("workflow")
+                wf_service.trg_validate(uid, 'l10n.es.aeat.mod340',
+                                        ids and ids[0], 'calculate', cr)
+
         except Exception, ex:
             raise
-        
-        
-        
+
+        if warn_message:
+            data_obj = self.pool.get('ir.model.data')
+            id2 = data_obj._get_id(cr, uid,
+                                   'l10n_es_aeat_mod340',
+                                   'view_warn_message')
+            if id2:
+                id2 = data_obj.browse(cr, uid, id2, context=context).res_id
+            return {
+                'view_type': 'form',
+                'view_mode': 'form',
+                'res_model': 'l10n.es.aeat.mod340.calculate_records',
+                'views': [(id2, 'form')],
+                'view_id': False,
+                'type': 'ir.actions.act_window',
+                'target': 'new',
+                'nodestroy': True,
+            }
+
         return True
 
-
-    def calculation_threading(self, cr, uid, ids, context=None):
-        if context is None:
-            context = {}
-
-        threaded_calculation = threading.Thread(target=self._calculate_records,
-                                                args=(cr, uid, ids, context))
-        threaded_calculation.start()
-
-        return {}
-
 l10n_es_aeat_mod340_calculate_records()

=== added file 'l10n_es_aeat_mod340/wizard/calculate_mod340_records_view.xml'
--- l10n_es_aeat_mod340/wizard/calculate_mod340_records_view.xml	1970-01-01 00:00:00 +0000
+++ l10n_es_aeat_mod340/wizard/calculate_mod340_records_view.xml	2014-04-23 13:41:23 +0000
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+		<record id="view_warn_message" model="ir.ui.view">
+			<field name="name">l10n.es.aeat.mod340.calculate_records.warn_message</field>   
+	        <field name="model">l10n.es.aeat.mod340.calculate_records</field>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+                <form string="Check data">
+                   <label string="Check the data, something is wrong" colspan="4"/>
+                   <button special="cancel" string="Accept" icon="gtk-ok" colspan="4"/>
+               </form>
+            </field>
+	    </record>
+    
+    </data>
+</openerp>
\ No newline at end of file


Follow ups