← Back to team overview

clearcorp team mailing list archive

[Merge] lp:~rr.clearcorp/openerp-costa-rica/6.1-l10n_cr_exchange_rates into lp:openerp-costa-rica/6.1

 

Ronald Rubi has proposed merging lp:~rr.clearcorp/openerp-costa-rica/6.1-l10n_cr_exchange_rates into lp:openerp-costa-rica/6.1.

Requested reviews:
  CLEARCORP drivers (clearcorp-drivers)

For more details, see:
https://code.launchpad.net/~rr.clearcorp/openerp-costa-rica/6.1-l10n_cr_exchange_rates/+merge/198432

[FIX] Fix adjustment, unreconcile accounts, l10n_cr_exchange_rates
-- 
https://code.launchpad.net/~rr.clearcorp/openerp-costa-rica/6.1-l10n_cr_exchange_rates/+merge/198432
Your team CLEARCORP development team is subscribed to branch lp:openerp-costa-rica/6.1.
=== modified file 'l10n_cr_exchange_rates/i18n/es_CR.po'
--- l10n_cr_exchange_rates/i18n/es_CR.po	2013-07-29 22:56:56 +0000
+++ l10n_cr_exchange_rates/i18n/es_CR.po	2013-12-10 16:15:35 +0000
@@ -6,8 +6,8 @@
 msgstr ""
 "Project-Id-Version: OpenERP Server 6.1\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-07-25 21:36+0000\n"
-"PO-Revision-Date: 2013-07-25 21:36+0000\n"
+"POT-Creation-Date: 2013-12-09 17:58+0000\n"
+"PO-Revision-Date: 2013-12-09 17:58+0000\n"
 "Last-Translator: <>\n"
 "Language-Team: \n"
 "MIME-Version: 1.0\n"
@@ -83,6 +83,12 @@
 msgstr "Cuenta"
 
 #. module: l10n_cr_exchange_rates
+#: code:addons/l10n_cr_exchange_rates/l10n_cr_exchange_rates.py:182
+#, python-format
+msgid "Unreconcile lines adjustment"
+msgstr "Ajuste de líneas no conciliables"
+
+#. module: l10n_cr_exchange_rates
 #: view:generate.exchange.rates.wizard:0
 msgid "Compute"
 msgstr "Crear"
@@ -104,6 +110,11 @@
 msgstr "Seleccione las opciones que necesita"
 
 #. module: l10n_cr_exchange_rates
+#: field:generate.exchange.rates.wizard,exchange_rate_date:0
+msgid "Exchange rate date"
+msgstr "Fecha del tipo de cambio"
+
+#. module: l10n_cr_exchange_rates
 #: sql_constraint:account.move.line:0
 msgid "Wrong credit or debit value in accounting entry !"
 msgstr "¡Valor haber o debe erróneo en el asiento contable!"
@@ -136,6 +147,11 @@
 "¡No se puede seleccionar un tipo de cuenta con un método diferente de aplazamiento \"no reconciliadas\" para las cuentas con el tipo interno \"por pagar / por cobrar\"! "
 
 #. module: l10n_cr_exchange_rates
+#: help:generate.exchange.rates.wizard,exchange_rate_date:0
+msgid "If not set, use the end of the period"
+msgstr "Si no se establece, utiliza la fecha final del período"
+
+#. module: l10n_cr_exchange_rates
 #: field:account.move.line,amount_exchange_rate:0
 msgid "Amount of exchange rate"
 msgstr "Importe de tipo de cambio"
@@ -164,7 +180,8 @@
 #: constraint:account.account:0
 msgid "Configuration Error! \n"
 "You can not define children to an account with internal type different of \"View\"! "
-msgstr "¡Error de configuración! "
+msgstr "¡Error de configuración! \n"
+"¡No se pueden definir los hijos de una cuenta con tipo interno diferente de \" vista \ "!"
 
 #. module: l10n_cr_exchange_rates
 #: view:generate.exchange.rates.wizard:0
@@ -172,7 +189,7 @@
 msgstr "Cancelar"
 
 #. module: l10n_cr_exchange_rates
-#: code:addons/l10n_cr_exchange_rates/wizard/l10n_cr_exchange_rates_wizard.py:51
+#: code:addons/l10n_cr_exchange_rates/wizard/l10n_cr_exchange_rates_wizard.py:55
 #, python-format
 msgid "Created Account Moves"
 msgstr "Asientos contables creados"
@@ -181,3 +198,4 @@
 #: field:account.move.line,adjustment:0
 msgid "Adjustment"
 msgstr "Ajuste"
+

=== modified file 'l10n_cr_exchange_rates/l10n_cr_exchange_rates.py'
--- l10n_cr_exchange_rates/l10n_cr_exchange_rates.py	2013-11-05 21:14:30 +0000
+++ l10n_cr_exchange_rates/l10n_cr_exchange_rates.py	2013-12-10 16:15:35 +0000
@@ -20,6 +20,7 @@
 #
 ##############################################################################
 
+import copy
 from osv import osv, fields
 from tools.translate import _
 
@@ -102,13 +103,15 @@
     def create_move_lines_reconcile(self, cr, uid, move, exchange_rate_end_period, context=None):
         move_line_obj = self.pool.get('account.move.line')
         account_account_obj = self.pool.get('account.account')
+        account_period_obj = self.pool.get('account.period')
         lines_created_ids = []
         account_reconcile_ids = account_account_obj.search(cr, uid, [('exchange_rate_adjustment', '=', True), ('reconcile', '=', True)], context=context)
-        line_reconcile_ids = move_line_obj.search(cr, uid, [('currency_id','!=',None), ('period_id','=',move.period_id.id), ('amount_currency','!=',0), ('account_id','in',account_reconcile_ids), ('adjustment','=',None), ('reconcile_id','=',None)], context=context)
+        periods_ids = account_period_obj.search(cr, uid, [('date_stop','<=',move.period_id.date_stop),('fiscalyear_id','=',move.period_id.fiscalyear_id.id)], context=context)
+        line_reconcile_ids = move_line_obj.search(cr, uid, [('currency_id','!=',None), ('period_id','in',periods_ids), ('amount_currency','!=',0), ('account_id','in',account_reconcile_ids), ('adjustment','=',None), ('reconcile_id','=',None)], context=context)
         lines_reconcile = move_line_obj.browse(cr, uid, line_reconcile_ids, context=context)
         
         for line in lines_reconcile:
-            if line.move_id.state == 'draft' or not line.amount_currency:
+            if not line.amount_currency:
                 continue
             
             sign_amount_currency = line.amount_currency < 0 and -1 or 1
@@ -135,7 +138,7 @@
                          'credit': credit,
                          'account_id':line.account_id.id,
                          'move_id': move.id,
-                         'period_id': line.period_id.id,
+                         'period_id': move.period_id.id,
                          'journal_id': line.journal_id.id,
                          'partner_id': line.partner_id.id,
                          'currency_id': line.account_id.currency_id.id,
@@ -152,65 +155,47 @@
     def create_move_lines_unreconcile(self, cr, uid, move, exchange_rate_end_period, context=None):
         move_line_obj = self.pool.get('account.move.line')
         account_account_obj = self.pool.get('account.account')
+        account_period_obj = self.pool.get('account.period')
+        
         lines_created_ids = []
-        account_unreconcile_ids = account_account_obj.search(cr, uid, [('exchange_rate_adjustment', '=', True), ('reconcile', '=', False)], context=context)
-
+        context_copy = copy.copy(context)
+        start_period_id = account_period_obj.search(cr, uid, [('fiscalyear_id','=',move.period_id.fiscalyear_id.id),('special','=',False)],order='date_start asc')[0]
+        context.update({'period_from':start_period_id, 'period_to':move.period_id.id})
+        
+        account_unreconcile_ids = account_account_obj.search(cr, uid, [('exchange_rate_adjustment', '=', True), ('reconcile', '=', False), ('currency_id', '!=', None)], context=context)
         for account_id in account_unreconcile_ids:
-            total_credit = 0.00
-            total_debit = 0.00
-            adjustment_lines = []
-            line_unreconcile_ids = move_line_obj.search(cr, uid, [('currency_id','!=',None), ('period_id','=',move.period_id.id), ('amount_currency','!=',0), ('account_id','=',account_id), ('adjustment','=',None)], context=context)
-            lines_unreconcile = move_line_obj.browse(cr, uid, line_unreconcile_ids, context=context)
-            for line in lines_unreconcile:
-                if line.move_id.state == 'draft' or not line.amount_currency:
-                    continue
-                
-                adjustment_lines.append(line.id)
-                sign_amount_currency = line.amount_currency < 0 and -1 or 1
-                line_difference = 0
-                if line.credit != 0:
-                    line_difference = sign_amount_currency * line.amount_currency * exchange_rate_end_period - line.credit
-                elif line.debit != 0:
-                    line_difference = sign_amount_currency * line.amount_currency * exchange_rate_end_period - line.debit
-                
-                sign = line_difference < 0 and -1 or 1
-                if line_difference == 0:
-                    continue
-                elif line.credit == 0 and exchange_rate_end_period > line.amount_exchange_rate or line.debit == 0 and exchange_rate_end_period < line.amount_exchange_rate:
-                    total_debit += sign * line_difference
-                else:
-                    total_credit += sign * line_difference
-            
+            res = account_account_obj._account_account__compute(cr, uid, [account_id], ['balance', 'foreign_balance'], context=context)
+            foreign_balance = res[account_id]['foreign_balance']
+            balance = res[account_id]['balance']
+            account_difference = abs(foreign_balance) * exchange_rate_end_period - abs(balance)
+            if account_difference > 0.0 and foreign_balance > 0.0 or account_difference < 0.0 and foreign_balance < 0.0:
+                total_debit = abs(account_difference)
+                total_credit = 0.0
+            elif account_difference < 0.0 and foreign_balance > 0.0 or account_difference > 0.0 and foreign_balance < 0.0:
+                total_debit = 0.0
+                total_credit = abs(account_difference)
+            else:
+                continue
+                
             account = account_account_obj.browse(cr, uid, account_id, context=context)
+            move_line = {
+                         'name': _('Unreconcile lines adjustment'),
+                         'debit': total_debit,
+                         'credit': total_credit,
+                         'account_id':account_id,
+                         'move_id': move.id,
+                         'period_id': move.period_id.id,
+                         'journal_id': move.journal_id.id,
+                         'partner_id': False,
+                         'currency_id': account.currency_id.id,
+                         'amount_currency': 0.00,
+                         'state': 'valid',
+                         'company_id': move.company_id.id,
+                         }
+            new_move_line_id = move_line_obj.create(cr, uid, move_line, context=context)
+            lines_created_ids.append(new_move_line_id)
             
-            if total_debit != 0.00 or total_credit != 0.00:
-                
-                if total_debit > total_credit:
-                    total_debit -= total_credit
-                    total_credit = 0.00
-                elif total_debit < total_credit:
-                    total_debit = 0.00
-                    total_credit -= total_debit
-                else:
-                    continue
-                
-                move_line = {
-                             'name': _('Unreconcile lines adjustment'),
-                             'debit': total_debit,
-                             'credit': total_credit,
-                             'account_id':account_id,
-                             'move_id': move.id,
-                             'period_id': move.period_id.id,
-                             'journal_id': move.journal_id.id,
-                             'currency_id': account.currency_id.id,
-                             'amount_currency': 0.00,
-                             'state': 'valid',
-                             'company_id': move.company_id.id,
-                             }
-                new_move_line_id = move_line_obj.create(cr, uid, move_line, context=context)
-                move_line_obj.write(cr, uid, adjustment_lines, {'adjustment' : new_move_line_id}, context=context)
-                lines_created_ids.append(new_move_line_id)
-        
+            context = context_copy
         return lines_created_ids
             
     def create_balance_line(self, cr, uid, move, res_user, name, context=None):    
@@ -233,6 +218,7 @@
                              'move_id': move.id,
                              'period_id': move.period_id.id,
                              'journal_id': move.journal_id.id,
+                             'partner_id': False,
                              'currency_id': False,
                              'amount_currency': 0.00,
                              'state': 'valid',
@@ -241,10 +227,11 @@
         new_move_line_id = move_line_obj.create(cr, uid, move_line, context=context)
         return new_move_line_id
     
-    def generate_adjustment_move(self, cr, uid, reference, journal, period, context=None):
+    def generate_adjustment_move(self, cr, uid, reference, journal, period, exchange_rate_date=False, context=None):
         res_currency_obj = self.pool.get('res.currency')
         res_currency_rate_obj = self.pool.get('res.currency.rate')
         res_user_obj = self.pool.get('res.users')
+        exchange_rate_end_period = 0.0
             
         res_user = res_user_obj.browse(cr, uid, uid, context=context)
         company_currency = res_user.company_id.currency_id
@@ -256,14 +243,17 @@
                     'period_id': period.id,
                     'to_check': False,
                     'company_id': res_user.company_id.id,
+                    'partner_id': False,
                     }
         move_created_id = self.create(cr, uid, move_created)
         move_created = self.browse(cr, uid, move_created_id, context=context)
-        
-        exchange_rate_end_period = res_currency_obj._current_rate(cr, uid, [company_currency.id], period.date_stop, arg=None, context=context)[company_currency.id]
+        if exchange_rate_date:
+            context.update({'date': exchange_rate_date,})
+            exchange_rate_end_period = res_currency_obj._current_rate(cr, uid, [company_currency.id], exchange_rate_date, arg=None, context=context)[company_currency.id]
+        else:
+            context.update({'date': period.date_stop,})
+            exchange_rate_end_period = res_currency_obj._current_rate(cr, uid, [company_currency.id], period.date_stop, arg=None, context=context)[company_currency.id]
         lines_reconcile_ids = self.create_move_lines_reconcile(cr, uid, move_created, exchange_rate_end_period, context=context)
-        print lines_reconcile_ids
         lines_unreconcile_ids = self.create_move_lines_unreconcile(cr, uid, move_created, exchange_rate_end_period, context=context)
         balance_line_id = self.create_balance_line(cr, uid, move_created, res_user, name, context=context)
         return move_created_id
-    

=== modified file 'l10n_cr_exchange_rates/l10n_cr_exchange_rates_view.xml'
--- l10n_cr_exchange_rates/l10n_cr_exchange_rates_view.xml	2013-07-29 22:56:56 +0000
+++ l10n_cr_exchange_rates/l10n_cr_exchange_rates_view.xml	2013-12-10 16:15:35 +0000
@@ -15,7 +15,7 @@
             <field name="type">form</field>
             <field name="arch" type="xml">
                 <field name="currency_mode" position="after">
-                    <field name="exchange_rate_adjustment" groups="base.group_extended"/>
+                    <field name="exchange_rate_adjustment" attrs="{'invisible': [('currency_id', '=', False), ('reconcile', '=', False)]}"/>
                 </field>
             </field>
         </record>

=== modified file 'l10n_cr_exchange_rates/wizard/l10n_cr_exchange_rates_wizard.py'
--- l10n_cr_exchange_rates/wizard/l10n_cr_exchange_rates_wizard.py	2013-07-29 22:56:56 +0000
+++ l10n_cr_exchange_rates/wizard/l10n_cr_exchange_rates_wizard.py	2013-12-10 16:15:35 +0000
@@ -30,6 +30,7 @@
         'reference': fields.char('Reference', size=256, required=True),
         'journal_id': fields.many2one('account.journal', 'Journal', required=True, help="Choose the journal for the move automatically generated"),
         'period_id': fields.many2one('account.period', 'Period', required=True, help="Choose the journal for the move automatically generated"),
+        'exchange_rate_date': fields.date('Exchange rate date', help="If not set, use the end of the period"),
     }
    
     def _get_period(self, cr, uid, context=None):
@@ -48,7 +49,8 @@
         reference = data[0].reference
         journal = data[0].journal_id
         period = data[0].period_id
-        created_move_id = account_move_obj.generate_adjustment_move(cr, uid, reference, journal, period, context=context)
+        exchange_rate_date = data[0].exchange_rate_date or False
+        created_move_id = account_move_obj.generate_adjustment_move(cr, uid, reference, journal, period, exchange_rate_date, context=context)
         return {
             'name': _('Created Account Moves'),
             'view_type': 'form',

=== modified file 'l10n_cr_exchange_rates/wizard/l10n_cr_exchange_rates_wizard.xml'
--- l10n_cr_exchange_rates/wizard/l10n_cr_exchange_rates_wizard.xml	2013-07-29 22:56:56 +0000
+++ l10n_cr_exchange_rates/wizard/l10n_cr_exchange_rates_wizard.xml	2013-12-10 16:15:35 +0000
@@ -11,11 +11,14 @@
                         <label string="This wizard will generates an move about exchange rate of the moves that belong to the selected period." colspan="4"/>
                         <newline/>
                         <field name="reference" colspan="4"/>
-                        <field name="journal_id"/>
+                        <group colspan="4" col="4">   
+                        <field name="journal_id" colspan="2"/>
                         <field name="period_id"/>
+                        <field name="exchange_rate_date"/>
+                        </group>
                         <separator colspan="4"/>
                         <group colspan="4" col="6">
-                           <label string="" colspan="2"/>
+                           <label string=""/>
                            <button icon="gtk-cancel" special="cancel" string="Cancel"/>
                            <button icon="gtk-execute" string="Compute" name="generate_exchange_rates" type="object"/>
                         </group>


Follow ups