~openerp-community/openobject-addons/synkronized.be_i10n_be_betaalmededeling

« back to all changes in this revision

Viewing changes to account/account_move_line.py

  • Committer: Jay(Open ERP)
  • Date: 2010-05-01 09:08:16 UTC
  • Revision ID: jvo@tinyerp.com-20100501090816-ozlzjed7ddpuuo9y
[FIX] Account : Added centralization check on write() of move line

Show diffs side-by-side

added added

removed removed

Lines of Context:
719
719
            result['arch'] = xml
720
720
            result['fields'] = self.fields_get(cr, uid, fields, context)
721
721
        return result
 
722
    
 
723
    def _check_moves(self, cr, uid, context):
 
724
        # use the first move ever created for this journal and period
 
725
        cr.execute('select id, state, name from account_move where journal_id=%s and period_id=%s order by id limit 1', (context['journal_id'],context['period_id']))
 
726
        res = cr.fetchone()
 
727
        if res:
 
728
            if res[1] != 'draft':
 
729
                raise osv.except_osv(_('UserError'),
 
730
                        _('The account move (%s) for centralisation ' \
 
731
                                'has been confirmed!') % res[2])
 
732
        return res
722
733
 
723
734
    def unlink(self, cr, uid, ids, context={}, check=True):
724
735
        self._update_check(cr, uid, ids, context)
732
743
        return result
733
744
 
734
745
    def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
735
 
        if not context:
736
 
            context={}
 
746
        if context is None:
 
747
            context = {}
737
748
        if vals.get('account_tax_id', False):
738
749
            raise osv.except_osv(_('Unable to change tax !'), _('You can not change the tax, you should remove and recreate lines !'))
739
750
 
748
759
        if vals.get('date', False):
749
760
            todo_date = vals['date']
750
761
            del vals['date']
 
762
 
 
763
        for line in self.browse(cr, uid, ids,context=context):
 
764
            ctx = context.copy()
 
765
            if ('journal_id' not in ctx):
 
766
                if line.move_id:
 
767
                    ctx['journal_id'] = line.move_id.journal_id.id
 
768
                else:
 
769
                    ctx['journal_id'] = line.journal_id.id
 
770
            if ('period_id' not in ctx):
 
771
                if line.move_id:
 
772
                    ctx['period_id'] = line.move_id.period_id.id
 
773
                else:
 
774
                    ctx['period_id'] = line.period_id.id  
 
775
            #Check for centralisation  
 
776
            journal = self.pool.get('account.journal').browse(cr, uid, ctx['journal_id'], context=ctx)
 
777
            if journal.centralisation:
 
778
                self._check_moves(cr, uid, context=ctx)
 
779
 
 
780
        
751
781
        result = super(account_move_line, self).write(cr, uid, ids, vals, context)
752
782
 
753
783
        if check:
813
843
        is_new_move = False
814
844
        if not move_id:
815
845
            if journal.centralisation:
816
 
                # use the first move ever created for this journal and period
817
 
                cr.execute('select id, state, name from account_move where journal_id=%s and period_id=%s order by id limit 1', (context['journal_id'],context['period_id']))
818
 
                res = cr.fetchone()
 
846
                #Check for centralisation
 
847
                res = self._check_moves(cr, uid, context)
819
848
                if res:
820
 
                    if res[1] != 'draft':
821
 
                        raise osv.except_osv(_('UserError'),
822
 
                                _('The account move (%s) for centralisation ' \
823
 
                                        'has been confirmed!') % res[2])
824
849
                    vals['move_id'] = res[0]
825
850
 
826
851
            if not vals.get('move_id', False):