← Back to team overview

clearcorp team mailing list archive

lp:~rr.clearcorp/openerp-ccorp-addons/6.1-account_voucher_reverse into lp:openerp-ccorp-addons

 

Ronald Rubi has proposed merging lp:~rr.clearcorp/openerp-ccorp-addons/6.1-account_voucher_reverse into lp:openerp-ccorp-addons.

Requested reviews:
  CLEARCORP drivers (clearcorp-drivers)

For more details, see:
https://code.launchpad.net/~rr.clearcorp/openerp-ccorp-addons/6.1-account_voucher_reverse/+merge/115629

[ADD] Add module account_move_reverse
-- 
https://code.launchpad.net/~rr.clearcorp/openerp-ccorp-addons/6.1-account_voucher_reverse/+merge/115629
Your team CLEARCORP development team is subscribed to branch lp:openerp-ccorp-addons.
=== added directory 'account_move_reverse'
=== added file 'account_move_reverse/__init__.py'
--- account_move_reverse/__init__.py	1970-01-01 00:00:00 +0000
+++ account_move_reverse/__init__.py	2012-07-18 22:08:19 +0000
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Addons modules by CLEARCORP S.A.
+#    Copyright (C) 2009-TODAY CLEARCORP S.A. (<http://clearcorp.co.cr>).
+#
+#    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 account_move_reverse
\ No newline at end of file

=== added file 'account_move_reverse/__openerp__.py'
--- account_move_reverse/__openerp__.py	1970-01-01 00:00:00 +0000
+++ account_move_reverse/__openerp__.py	2012-07-18 22:08:19 +0000
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Addons modules by CLEARCORP S.A.
+#    Copyright (C) 2009-TODAY CLEARCORP S.A. (<http://clearcorp.co.cr>).
+#
+#    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/>.
+#
+##############################################################################
+
+{
+    "name" : "Account Move Reverse",
+    "version" : '1.0',
+    "author" : 'CLEARCORP S.A.',
+    'complexity': 'normal',
+    "description": """
+Module for reverse account move
+    """,
+    "category": 'Accounting & Finance',
+    "sequence": 4,
+    "website" : "http://clearcorp.co.cr";,
+    "images" : [],
+    "icon" : False,
+    "depends" : ["account_voucher"],
+    "init_xml" : [],
+    "demo_xml" : [],
+    "update_xml" : [],
+    "test" : [],
+    "auto_install": False,
+    "application": False,
+    "installable": True,
+    'license': 'AGPL-3',
+}

=== added file 'account_move_reverse/account_move_reverse.py'
--- account_move_reverse/account_move_reverse.py	1970-01-01 00:00:00 +0000
+++ account_move_reverse/account_move_reverse.py	2012-07-18 22:08:19 +0000
@@ -0,0 +1,123 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Addons modules by CLEARCORP S.A.
+#    Copyright (C) 2009-TODAY CLEARCORP S.A. (<http://clearcorp.co.cr>).
+#
+#    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/>.
+#
+##############################################################################
+
+from osv import orm, osv, fields
+
+class account_move(orm.Model):
+
+    _inherit = 'account.move'
+
+    _columns = {
+                'move_reverse_id':fields.many2one('account.move','Move Reverse'),
+                }
+
+    def copy(self, cr, uid, id, default={}, context=None):
+        default.update({
+            'move_reverse_id':False,
+        })
+
+    def button_cancel(self, cr, uid, ids, context=None):
+        for move in self.browse(cr, uid, ids, context=context):
+            if not move.journal_id.update_posted:
+                raise osv.except_osv(_('Error !'), _('You can not modify a posted entry of this journal !\nYou should set the journal to allow cancelling entries if you want to do that.'))
+
+            if move.move_reverse_id:
+                move_reverse = self.browse(cr, uid, move.move_reverse_id.id, context=context)
+                
+                for line_reverse in move_reverse.line_id:
+                    if line_reverse.reconcile_id:
+                        self.pool.get('account.move.reconcile').unlink(cr,uid,[line_reverse.reconcile_id.id],context=context)
+                cr.execute('UPDATE account_move '\
+                           'SET state=%s '\
+                           'WHERE id IN %s', ('draft', tuple([move_reverse.id]),))
+                self.unlink(cr,uid,[move_reverse.id],context=context)
+
+        result = super(account_move, self).button_cancel(cr, uid, ids, context=context)
+        return True
+
+    def reverse(self, cr, uid, ids, context=None):
+
+        for move_original_id in ids:
+            move_original = self.pool.get('account.move').browse(cr, 1, move_original_id, context=context)
+
+            move = {
+                    'name':'Reverse: ' + move_original.name,
+                    'ref':move_original.ref,
+                    'journal_id':move_original.journal_id.id,
+                    'period_id':move_original.period_id.id,
+                    'to_check':False,
+                    'partner_id':move_original.partner_id.id,
+                    'date':move_original.date,
+                    'narration':move_original.narration,
+                    'company_id':move_original.company_id.id,
+                    }
+            move_id = self.pool.get('account.move').create(cr, uid, move)
+                    
+            self.pool.get('account.move').write(cr, uid, [move_original.id], {'move_reverse_id' : move_id})
+
+            move_reconcile_obj = self.pool.get('account.move.reconcile')
+
+            lines = move_original.line_id
+            for line in lines:
+                move_line = {
+                             'name':line.name,
+                             'debit':line.credit,
+                             'credit':line.debit,
+                             'account_id':line.account_id.id,
+                             'move_id': move_id,
+                             'amount_currency':line.amount_currency * -1,
+                             'period_id':line.period_id.id,
+                             'journal_id':line.journal_id.id,
+                             'partner_id':line.partner_id.id,
+                             'currency_id':line.currency_id.id,
+                             'date_maturity':line.date_maturity,
+                             'date':line.date,
+                             'date_created':line.date_created,
+                             'state':'valid',
+                             'company_id':line.company_id.id,
+                             }
+
+                line_created_id = self.pool.get('account.move.line').create(cr, uid, move_line)
+
+                if line.reconcile_id:
+                    reconcile = line.reconcile_id
+                    if len(reconcile.line_id) > 2:
+                        self.pool.get('account.move.line').write(cr,uid,reconcile.line_id,{'reconcile_id': False, 'reconcile_partial_id':reconcile.id})
+                        self.pool.get('account.move.line').write(cr,uid,line.id,{'reconcile_partial_id': False})
+                    else:
+                        move_reconcile_obj.unlink(cr,uid,[reconcile.id],context=context)
+
+                elif line.reconcile_partial_id:
+                    reconcile = line.reconcile_partial_id
+                    if len(reconcile.line_partial_ids) > 2:
+                        self.pool.get('account.move.line').write(cr,uid,line.id,{'reconcile_partial_id': False })
+                    else:
+                        move_reconcile_obj.unlink(cr,uid,[reconcile.id],context=context)
+
+                if line.account_id.reconcile:
+                    reconcile_id = self.pool.get('account.move.reconcile').create(cr, uid, {'type': 'Account Reverse'})
+                    self.pool.get('account.move.line').write(cr,uid,[line.id],{'reconcile_id': reconcile_id})
+                    self.pool.get('account.move.line').write(cr,uid,[line_created_id],{'reconcile_id': reconcile_id})
+
+            #Posted move reverse
+            self.pool.get('account.move').post(cr, 1, [move_id, move_original.id], context={})
+        return True

=== modified file 'account_multicompany_relation/__openerp__.py'
--- account_multicompany_relation/__openerp__.py	2012-06-30 22:41:06 +0000
+++ account_multicompany_relation/__openerp__.py	2012-07-18 22:08:19 +0000
@@ -1,8 +1,29 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Addons modules by CLEARCORP S.A.
+#    Copyright (C) 2009-TODAY CLEARCORP S.A. (<http://clearcorp.co.cr>).
+#
+#    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/>.
+#
+##############################################################################
 {
 	"name" : "Account Multicompany Relation",
 	"author" : "CLEARCORP S.A",
 	"version" : "0.1",
-	"depends" : ["account_voucher"],
+	"depends" : ["account_voucher_reverse"],
 	"init_xml" : [],
 	"update_xml" : [
 		"account_multicompany_relation.xml"

=== modified file 'account_multicompany_relation/account_multicompany_relation.py'
--- account_multicompany_relation/account_multicompany_relation.py	2012-06-30 22:41:06 +0000
+++ account_multicompany_relation/account_multicompany_relation.py	2012-07-18 22:08:19 +0000
@@ -21,17 +21,19 @@
 from osv import orm, fields
 from copy import copy
 
-class AccountMulticompanyRelation(orm.Model):
+class account_multicompany_relation(orm.Model):
 
     _name = "account.multicompany.relation"
     _description = "Account multicompany relation"
 
     _columns = {
-        'name'              : fields.char('Name',size=64,required=True,help='Name for the mirror object relation'),
-        'origin_account'    : fields.many2one('account.account','Original Account',required=True,help='Indicate the original account where the transaction is taking place'),
-        'targ_account'      : fields.many2one('account.account','Target Account',required=True,help='Indicate the target account where the transaction of the original account has to be seen, this is an account from another company'),
-        'origin_journal'    : fields.many2one('account.journal','Original Journal',required=True,help='Indicate the original journal where the transaction is taking place'),
-        'targ_journal'      : fields.many2one('account.journal','Target Journal',required=True,help='Indicate the original account where the transaction is taking place'),
+        'name':fields.char('Name',size=64,required=True,help='Name for the mirror object relation'),
+        'origin_account':fields.many2one('account.account','Original Account',required=True,help='Indicate the original account where the transaction is taking place'),
+        'targ_account':fields.many2one('account.account','Target Account',required=True,help='Indicate the target account where the transaction of the original account has to be seen, this is an account from another company'),
+        'origin_journal':fields.many2one('account.journal','Original Journal',required=True,help='Indicate the original journal where the transaction is taking place'),
+        'targ_journal':fields.many2one('account.journal','Target Journal',required=True,help='Indicate the original account where the transaction is taking place'),
+        'origin_analytic_account':fields.many2one('account.analytic.account','Original Analytic Account',required=False,help='Indicate the original analytic account where the transaction is taking place'),
+        'targ_analytic_account':fields.many2one('account.analytic.account','Target Analytic Account',required=False,help='Indicate the target analytic account where the transaction of the original analytic account has to be seen, this is an analytic account from another company'),
     }
 
     _sql_constraints = [
@@ -41,129 +43,207 @@
             'The name must be unique'
         ),
         (
-            'unique_journal_account_origins',
-            'unique(origin_account,origin_journal)',
-            'A relation exists already with this origin journal and origin account'
-        )
-    ]
-
-
-class AccountVoucher(orm.Model):
-
-    _inherit = 'account.voucher'
-
-    def proforma_voucher(self, cr, uid, ids, context=None):
-        result = super(AccountVoucher, self).action_move_line_create(cr, uid, ids, context=context)
-
-        # Initialize voucher variables and check if voucher has a move, a journal and an account
-        # If not, exit and return original result
-        voucher = self.browse(cr,1,ids,context=context)[0]
-        if not voucher.move_id:
-            return result
-        if voucher and voucher.account_id and voucher.journal_id:
-            voucher_account = voucher.account_id.id
-            voucher_journal = voucher.journal_id.id
-        else:
-            return result
-
-        # Search for a compliant mirror relation, if none found exit returning the original result
-        mirror_journal_list = self.pool.get('account.multicompany.relation').search(cr, 1, [('origin_account', '=', voucher_account), ('origin_journal', '=', voucher_journal)], context=context)
-        if len(mirror_journal_list) > 0:
-            mirror_journal_id = mirror_journal_list[0]
-        else:
-            return result
-
-        # Read mirror relation data and check if mirror origin account is in the voucher move
-        # If not exit returning the original result
-        mirror_journal = self.pool.get('account.multicompany.relation').browse(cr, 1, [mirror_journal_id], context=context)[0]
-        origin_journal = mirror_journal.origin_journal
-        origin_account = mirror_journal.origin_account
-        targ_journal =  mirror_journal.targ_journal
-        targ_account = mirror_journal.targ_account
-
-        original_move = voucher.move_id
-        
-        if not original_move.line_id:
-            return result
-
-        list_ = []
-        lines = original_move.line_id
-        for line in lines:
-            if line.account_id and line.account_id.id == origin_account.id:
-                list_.append(line)
-
-        if len(list_) != 1:
-            return result
-
-        #Set period for target move with the correct company
-        if context == None:
-            context_copy = {'company_id': targ_account.company_id.id}
-        else:
-            context_copy = copy(context)
-            context_copy.update({'company_id': targ_account.company_id.id})
-        periods = self.pool.get('account.period').find(cr, 1, dt=original_move.date, context=context_copy)
-        if periods:
-            move_period = periods[0]
-
-        move = {
-            'name':'MCR: ' + original_move.name,
-            'ref':original_move.ref,
-            'journal_id':targ_journal.id,
-            'period_id':move_period or False,
-            'to_check':False,
-            'partner_id':original_move.partner_id.id,
-            'date':original_move.date,
-            'narration':original_move.narration,
-            'company_id':targ_account.company_id.id,
-        }
-        move_id = self.pool.get('account.move').create(cr, 1, move)
-
-        move_line_original = list_[0]
-
-        move_line_one = {
-            'name':move_line_original.name,
-            'debit':move_line_original.credit,
-            'credit':move_line_original.debit,
-            'account_id':targ_account.id,
-            'move_id': move_id,
-            'amount_currency':move_line_original.amount_currency * -1,
-            'period_id':move_period or False,
-            'journal_id':targ_journal.id,
-            'partner_id':move_line_original.partner_id.id,
-            'currency_id':move_line_original.currency_id.id,
-            'date_maturity':move_line_original.date_maturity,
-            'date':move_line_original.date,
-            'date_created':move_line_original.date_created,
-            'state':'valid',
-            'company_id':targ_account.company_id.id,
-        }
-
-        self.pool.get('account.move.line').create(cr, 1, move_line_one)
-        if move_line_original.debit != 0.0:
-            move_line_two_account_id = targ_journal.default_credit_account_id
-        else:
-            move_line_two_account_id = targ_journal.default_debit_account_id
-
-        move_line_two = {
-            'name':move_line_original.name,
-            'debit':move_line_original.debit,
-            'credit':move_line_original.credit,
-            'account_id':move_line_two_account_id.id,
-            'move_id': move_id,
-            'amount_currency':move_line_original.amount_currency,
-            'journal_id':targ_journal.id,
-            'period_id':move_period or False,
-            'partner_id':move_line_original.partner_id.id,
-            'currency_id':move_line_original.currency_id.id,
-            'date_maturity':move_line_original.date_maturity,
-            'date':move_line_original.date,
-            'date_created':move_line_original.date_created,
-            'state':'valid',
-            'company_id':targ_account.company_id.id,
-        }
-
-        self.pool.get('account.move.line').create(cr, 1, move_line_two)
-        
-        if (targ_journal.entry_posted):
-            self.pool.get('account.move').post(cr, 1, [move_id], context={})
+            'unique_mirror_relation',
+            'unique(origin_account,origin_journal,origin_analytic_account)',
+            'A relation exists already'
+        )
+    ]
+
+    def _check_unique_mirror_relation(self, cr, uid, ids, context=None):
+        exist = False
+        all_mirrors_ids = self.search(cr, uid, [], context)
+        all_mirrors = self.browse(cr, uid, all_mirrors_ids, context)
+        for mirror_id in ids:
+            mirror = self.browse(cr, uid, mirror_id, context)
+            if not mirror.origin_analytic_account:
+                for current_mirror in all_mirrors:
+                    if current_mirror.origin_account.id == mirror.origin_account.id and current_mirror.origin_journal.id == mirror.origin_journal.id:
+                        if not current_mirror.origin_analytic_account:
+                            return False
+        return True
+
+    _constraints = [
+        (
+            _check_unique_mirror_relation,
+            'A relation exists already', ['origin_analytic_account']
+        )
+    ]
+
+
+class account_move(orm.Model):
+
+    _inherit = 'account.move'
+    
+    _columns = {
+                'move_mirror_rel_id':fields.many2one('account.move','Move Multicompany Relation'),
+                }
+
+    def copy(self, cr, uid, id, default={}, context=None):
+        default.update({
+            'move_mirror_rel_id':False,
+        })
+
+    def button_cancel(self, cr, uid, ids, context=None):
+        self.pool.get('account.move.reconcile')
+        for move in self.browse(cr, uid, ids, context=context):
+            if not move.journal_id.update_posted:
+                raise osv.except_osv(_('Error !'), _('You can not modify a posted entry of this journal !\nYou should set the journal to allow cancelling entries if you want to do that.'))
+
+            #Set user administrator to run this portion of code
+            uid = 1
+            if move.move_mirror_rel_id:
+                move_mirror = self.browse(cr, uid, move.move_mirror_rel_id.id, context=context)
+                if not move_mirror.journal_id.update_posted:
+                    raise osv.except_osv(_('Error !'), _('You can not modify a posted multicompany mirror entry of this journal !\nYou should set the journal to allow cancelling entries if you want to do that.'))
+
+                move_reconcile_obj = self.pool.get('account.move.reconcile')
+                for line_mirror in move_mirror.line_id:
+                    if line_mirror.reconcile_id:
+                        reconcile = line_mirror.reconcile_id
+                        if len(reconcile.line_id) > 2:
+                            self.pool.get('account.move.line').write(cr,uid,reconcile.line_id,{'reconcile_id': False, 'reconcile_partial_id':reconcile.id})
+                            self.pool.get('account.move.line').write(cr,uid,line_mirror.id,{'reconcile_partial_id': False})
+                        else:
+                            move_reconcile_obj.unlink(cr,uid,[reconcile.id],context=context)
+
+                    elif line_mirror.reconcile_partial_id:
+                        reconcile = line_mirror.reconcile_partial_id
+                        if len(reconcile.line_partial_ids) > 2:
+                            self.pool.get('account.move.line').write(cr,uid,line_mirror.id,{'reconcile_partial_id': False })
+                        else:
+                            move_reconcile_obj.unlink(cr,uid,[reconcile.id],context=context)
+
+                cr.execute('UPDATE account_move '\
+                           'SET state=%s '\
+                           'WHERE id IN %s', ('draft', tuple([move_mirror.id]),))
+                self.button_cancel(cr,uid,[move_mirror.id],context=context)
+                self.unlink(cr,uid,[move_mirror.id],context=context)
+
+        result = super(account_move, self).button_cancel(cr, uid, ids, context=context)
+        return True
+
+    def post(self, cr, uid, ids, context=None):
+        result = super(account_move, self).post(cr, uid, ids, context=context)
+
+        for move_id_original in ids:
+            if self.pool.get('account.move').search(cr, 1, [('move_reverse_id', '=', move_id_original)], context=context):
+                continue
+                            
+            original_move = self.pool.get('account.move').browse(cr, 1, move_id_original, context=context)
+            move_id = False
+
+            move_lines_ids = self.pool.get('account.move.line').search(cr, 1, [('move_id', '=', move_id_original)], context=context)
+            if move_lines_ids:
+                lines = self.pool.get('account.move.line').browse(cr, 1, move_lines_ids, context=context)
+    
+                mirror_selected = False
+            
+                for line in lines:
+                    mirror_selected_list_ids = self.pool.get('account.multicompany.relation').search(cr, 1, [('origin_account', '=', line.account_id.id), ('origin_journal', '=', line.journal_id.id)], context=context)
+                    if len(mirror_selected_list_ids) > 0:
+                        mirror_selected_list = self.pool.get('account.multicompany.relation').browse(cr, 1, mirror_selected_list_ids, context=context)
+    
+                        for mirror in mirror_selected_list:
+                            if line.account_id and line.account_id.id == mirror.origin_account.id and line.journal_id.id == mirror.origin_journal.id:
+                                if mirror.origin_analytic_account:
+                                    if line.analytic_account_id and line.analytic_account_id.id == mirror.origin_analytic_account:
+                                        mirror_selected = mirror
+                                        break
+                                elif not mirror_selected:
+                                    mirror_selected = mirror
+                    
+                        if mirror_selected:
+                            origin_journal = mirror_selected.origin_journal
+                            origin_account = mirror_selected.origin_account
+                            targ_journal =  mirror_selected.targ_journal
+                            targ_account = mirror_selected.targ_account
+                        else:
+                            return result
+                                
+                        #Set period for target move with the correct company
+                        if context == None:
+                            context_copy = {'company_id': targ_account.company_id.id}
+                        else:
+                            context_copy = copy(context)
+                            context_copy.update({'company_id': targ_account.company_id.id})
+                
+                        periods = self.pool.get('account.period').find(cr, 1, dt=original_move.date, context=context_copy)
+                        if periods:
+                            move_period = periods[0]
+        
+                        move = {
+                                'name':'MCR: ' + original_move.name,
+                                'ref':original_move.ref,
+                                'journal_id':targ_journal.id,
+                                'period_id':move_period or False,
+                                'to_check':False,
+                                'partner_id':original_move.partner_id.id,
+                                'date':original_move.date,
+                                'narration':original_move.narration,            
+                                'company_id':targ_account.company_id.id,
+                                }
+                        move_id = self.pool.get('account.move').create(cr, 1, move)
+                        self.pool.get('account.move').write(cr, uid, [original_move.id], {'move_mirror_rel_id' : move_id})
+        
+                        analytic_account_id = ''
+                        if line.analytic_account_id and line.analytic_account_id == mirror_selected.origin_analytic_account:
+                            analytic_account_id = mirror_selected.targ_analytic_account.id
+        
+                        move_line_one = {
+                                         'name':line.name,
+                                         'debit':line.credit,
+                                         'credit':line.debit,
+                                         'account_id':targ_account.id,
+                                         'move_id': move_id,
+                                         'amount_currency':line.amount_currency * -1,
+                                         'period_id':move_period or False,
+                                         'journal_id':targ_journal.id,
+                                         'partner_id':line.partner_id.id,
+                                         'currency_id':line.currency_id.id,
+                                         'date_maturity':line.date_maturity,
+                                         'date':line.date,
+                                         'date_created':line.date_created,
+                                         'state':'valid',
+                                         'analytic_account_id':analytic_account_id,
+                                         'company_id':targ_account.company_id.id,
+                                         }
+        
+                        self.pool.get('account.move.line').create(cr, 1, move_line_one)
+                        if line.debit != 0.0:
+                            move_line_two_account_id = targ_journal.default_credit_account_id
+                        else:
+                            move_line_two_account_id = targ_journal.default_debit_account_id
+        
+                        move_line_two = {
+                                         'name':line.name,
+                                         'debit':line.debit,
+                                         'credit':line.credit,
+                                         'account_id':move_line_two_account_id.id,
+                                         'move_id': move_id,
+                                         'amount_currency':line.amount_currency,
+                                         'journal_id':targ_journal.id,
+                                         'period_id':move_period or False,
+                                         'partner_id':line.partner_id.id,
+                                         'currency_id':line.currency_id.id,
+                                         'date_maturity':line.date_maturity,
+                                         'date':line.date,
+                                         'date_created':line.date_created,
+                                         'state':'valid',
+                                         'analytic_account_id':analytic_account_id,
+                                         'company_id':targ_account.company_id.id,
+                                         }
+                        self.pool.get('account.move.line').create(cr, 1, move_line_two)
+                        
+                        #Posted mirror
+                        self.pool.get('account.move').post(cr, 1, [move_id], context={})
+            if move_id and original_move.move_reverse_id:
+                self.pool.get('account.move').reverse(cr, 1, [move_id], context={})
+        return result
+    
+    def unlink(self, cr, uid, ids, context=None, check=True):
+        for move in self.browse(cr, 1, ids, context=context):
+            if move.move_mirror_rel_id:
+                self.pool.get('account.move').button_cancel(cr, 1, [move.move_mirror_rel_id.id])
+                result = super(account_move, self).unlink(cr, 1, [move.move_mirror_rel_id.id], context=context, check=check)
+        result = super(account_move, self).unlink(cr, 1, ids, context=context, check=check)
         return result

=== modified file 'account_multicompany_relation/account_multicompany_relation.xml'
--- account_multicompany_relation/account_multicompany_relation.xml	2012-06-30 22:41:06 +0000
+++ account_multicompany_relation/account_multicompany_relation.xml	2012-07-18 22:08:19 +0000
@@ -14,6 +14,8 @@
                     <field name = "targ_account"/>
                     <field name = "origin_journal"/>
                     <field name = "targ_journal"/>
+                    <field name = "origin_analytic_account"/>
+                    <field name = "targ_analytic_account"/>
                 </form>
             </field>
         </record>
@@ -29,6 +31,8 @@
                     <field name = "targ_account"/>
                     <field name = "origin_journal"/>
                     <field name = "targ_journal"/>
+                    <field name = "origin_analytic_account"/>
+                    <field name = "targ_analytic_account"/>
                 </tree>
             </field>
         </record>

=== modified file 'account_voucher_reverse/__openerp__.py'
--- account_voucher_reverse/__openerp__.py	2012-07-04 22:55:47 +0000
+++ account_voucher_reverse/__openerp__.py	2012-07-18 22:08:19 +0000
@@ -33,7 +33,7 @@
     "website" : "http://clearcorp.co.cr";,
     "images" : [],
     "icon" : False,
-    "depends" : ["account_voucher"],
+    "depends" : ["account_move_reverse"],
     "init_xml" : [],
     "demo_xml" : [],
     "update_xml" : [

=== modified file 'account_voucher_reverse/account_voucher_reverse.py'
--- account_voucher_reverse/account_voucher_reverse.py	2012-07-04 22:55:47 +0000
+++ account_voucher_reverse/account_voucher_reverse.py	2012-07-18 22:08:19 +0000
@@ -42,90 +42,12 @@
     }
 
     def reverse_voucher(self, cr, uid, ids, context=None):
-
-        self.write(cr, uid, ids, {'state' : 'reverse'}, context=context)
-
-        #To create a move reverse
-        self.account_voucher_move_reverse(cr, uid, ids, context=context)
-        
-        return True
-
-    def account_voucher_move_reverse(self, cr, uid, ids, context=None):
-        # Initialize voucher variables and check if voucher has a move, a journal and an account
-        # If not, exit and return original result
-        voucher = self.browse(cr,uid,ids,context=context)[0]
-        if not voucher.move_id:
-            return False
-
-        original_move = voucher.move_id
-        
-        if not original_move.line_id:
-            return False
-
-        move = {
-            'name':'Reverse: ' + original_move.name,
-            'ref':original_move.ref,
-            'journal_id':original_move.journal_id.id,
-            'period_id':original_move.period_id.id,
-            'to_check':False,
-            'partner_id':original_move.partner_id.id,
-            'date':original_move.date,
-            'narration':original_move.narration,
-            'company_id':original_move.company_id.id,
-        }
-        move_id = self.pool.get('account.move').create(cr, uid, move)
-
-        move_reconcile_obj = self.pool.get('account.move.reconcile')
-
-        lines = original_move.line_id
-        for line in lines:
-            move_line = {
-                'name':line.name,
-                'debit':line.credit,
-                'credit':line.debit,
-                'account_id':line.account_id.id,
-                'move_id': move_id,
-                'amount_currency':line.amount_currency * -1,
-                'period_id':line.period_id.id,
-                'journal_id':line.journal_id.id,
-                'partner_id':line.partner_id.id,
-                'currency_id':line.currency_id.id,
-                'date_maturity':line.date_maturity,
-                'date':line.date,
-                'date_created':line.date_created,
-                'state':'valid',
-                'company_id':line.company_id.id,
-            }
-
-            line_created_id = self.pool.get('account.move.line').create(cr, uid, move_line)
-            
-            if (original_move.journal_id.entry_posted):
-                self.pool.get('account.move').post(cr, uid, [move_id], context={})
-
-            if line.reconcile_id:
-                reconcile = move_reconcile_obj.browse(cr,uid,[line.reconcile_id.id],context=context)[0]
-                if len(reconcile.line_id) > 2:
-                    self.pool.get('account.move.line').write(cr,uid,line.id,{'reconcile_id': False })
-                    for line in reconcile.line_id:
-                        self.pool.get('account.move.line').write(cr,uid,line.id,{'reconcile_id': False,'reconcile_partial_id':line.reconcile_id.id})
-                else:
-                    move_reconcile_obj.unlink(cr,uid,[line.reconcile_id.id],context=context)
-            
-            if line.reconcile_partial_id:
-                reconcile = move_reconcile_obj.browse(cr,uid,[line.reconcile_partial_id.id],context=context)[0]
-                if len(reconcile.line_partial_ids) > 2:
-                    self.pool.get('account.move.line').write(cr,uid,line.id,{'reconcile_partial_id': False })
-                else:
-                    move_reconcile_obj.unlink(cr,uid,[line.reconcile_partial_id.id],context=context)
-
-            if line.account_id.reconcile:
-                reconcile_id = self.pool.get('account.move.reconcile').create(cr, uid, {'type': 'Account Reverse'})
-                self.pool.get('account.move.line').write(cr,uid,[line.id],{'reconcile_id': reconcile_id})
-                self.pool.get('account.move.line').write(cr,uid,[line_created_id],{'reconcile_id': reconcile_id})
-
-        return True
-
-
+        for voucher_id in ids:
+            voucher = self.pool.get('account.voucher').browse(cr, 1, voucher_id, context=context)
+            if voucher.move_id:
+                self.pool.get('account.move').reverse(cr, uid, [voucher.move_id.id], context=context)
+            self.write(cr, uid, [voucher_id], {'state' : 'reverse'}, context=context)
+        return {}
 
 
 


Follow ups