~openerp-chinese-team/openerp-china/openerp-china

« back to all changes in this revision

Viewing changes to oecn_account_print/report/oecn_account_print_report.py

  • Committer: JoshuaJan
  • Date: 2012-02-21 11:25:47 UTC
  • Revision ID: joshua@openerp.cn-20120221112547-zby6tz55xrj0asmk
Add stock ledger

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
        self.all_date = self._get_date(data)
89
89
        data['all_date'] = self.all_date
90
90
        new_ids = ids
91
 
        print 'ids:%s date:%s'%(ids, data)
92
91
        objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids)
93
92
 
94
93
        super(general_ledger_parser, self).set_context(objects, data, new_ids, report_type)
119
118
        """
120
119
        根据日期段获取里面的期间
121
120
        """
122
 
        print 'in_get_period'
123
121
        self.cr.execute(("select date_start,date_stop,name as period_name "\
124
122
                    "from account_period where "\
125
123
                    " date_start>='%s' and date_stop<='%s' "\
126
124
                    " order by date_start")% (self.all_date['period_start_date_start'], self.all_date['period_end_date_stop']))
127
125
        periods = self.cr.dictfetchall()
128
 
        print 'peirod---->:',periods
129
126
        return periods
130
127
 
131
128
    def _beginning_balance_accounts(self, account):
132
129
        """
133
130
        计算年初,借、贷、余额
134
131
        """
135
 
        print '_beginning_balance_accounts'
136
132
        periods = self._get_periods()
137
 
        print 'account:',account
138
133
        account_ids = account.id
139
134
        result={
140
135
            'debit':0,
171
166
                result['debit']=res[0]['debit']
172
167
                result['credit']=res[0]['credit']
173
168
                result['balance']=res[0]['balance']
174
 
        print 'result:',result
175
169
        return result
176
170
 
177
171
    def _general_ledger_line(self, account):
278
272
            'time': time,
279
273
            'lines': self._get_lines,
280
274
            'type':self._check_type,
281
 
            'period_date':self.get_dete,
 
275
            'period_date':self.get_date,
282
276
            'contrepartie':self._calc_contrepartie,
283
277
            # 'sum_debit_account': self._sum_debit_account,
284
278
            # 'sum_credit_account': self._sum_credit_account,
310
304
        设置 OE context
311
305
        """
312
306
        # self.borne_date = self.get_date(data['form'])
313
 
        print 'data-->',data
314
 
        self.all_dete = self.get_dete(data)
 
307
        self.all_date = self.get_date(data)
315
308
        self.sql_condition = self.get_threecolumns_ledger_type(data)
316
 
        print 'ids:',ids
 
309
        print 'all_date:%s----sql:%s'%(self.all_date, self.sql_condition)
317
310
        #new_ids = []
318
311
        #if (data.get('model', False) == 'account.account'):
319
312
        #    new_ids = ids
323
316
 
324
317
        super(detail_ledger_parser, self).set_context(objects, data, ids, report_type)
325
318
 
326
 
    def get_dete(self, data):
 
319
    def get_date(self, data):
327
320
        """
328
321
        分析日期
329
322
        """
330
 
        print 'date:-->',data
331
323
        period_obj = self.pool.get('account.period')
332
324
        period_start_obj = period_obj.browse(self.cr, self.uid, data['period_from'][0])
333
 
        print 'period_start_obj:',period_start_obj
334
325
        period_end_obj = period_obj.browse(self.cr, self.uid, data['period_to'][0])
335
326
        fiscalyear_obj = self.pool.get('account.fiscalyear').browse(self.cr, self.uid, period_start_obj.fiscalyear_id.id)
336
 
        self.all_dete = {
 
327
        self.all_date = {
337
328
            'period_start_date_start':period_start_obj.date_start,
338
329
            'period_end_date_stop':period_end_obj.date_stop,
339
330
            'fiscalyear_obj_date_start':fiscalyear_obj.date_start,
340
331
        }
341
332
 
342
 
        return self.all_dete
 
333
        return self.all_date
343
334
 
344
335
    def _get_periods(self):
345
336
        """
346
337
        获取期间
347
338
        """
348
339
        period_obj = self.pool.get('account.period')
349
 
        period_ids = period_obj.search(self.cr, self.uid, [('date_start','>=',self.all_dete['period_start_date_start']),('date_stop','<=',self.all_dete['period_end_date_stop'])], order='date_start')
 
340
        period_ids = period_obj.search(self.cr, self.uid, [('date_start','>=',self.all_date['period_start_date_start']),('date_stop','<=',self.all_date['period_end_date_stop'])], order='date_start')
350
341
        periods = period_obj.browse(self.cr, self.uid, period_ids)
351
342
        return periods
352
343
 
354
345
        """
355
346
        检测报表类型
356
347
        """
357
 
        print 'data:',data
358
348
        res = {}
359
349
        res['product'] = ""
360
350
        res['partner'] = ""
376
366
        result = {}
377
367
        #for id in ids:
378
368
        #    result.setdefault(id, False)
379
 
      
380
369
        for account_line in self.pool.get('account.move.line').browse(self.cr, self.uid, ids, context):
381
370
            # For avoid long text in the field we will limit it to 5 lines
382
 
            print 'account_line------>',account_line
383
371
            result[account_line.id] = ' '
384
372
            num_id_move = str(account_line.move_id.id)
385
373
            num_id_line = str(account_line.id)
390
378
            self.cr.execute('SELECT distinct(ac.code) as code_rest,ac.name as name_rest from account_account AS ac, account_move_line mv\
391
379
                    where ac.id = mv.account_id and mv.move_id = ' + num_id_move +' and mv.account_id <> ' + account_id )
392
380
            res_mv = self.cr.dictfetchall()
393
 
            print 'res_mv',res_mv
394
381
            # we need a result more than 2 line to make the test so we will made the the on 1 because we have exclude the current line
395
382
            if (len(res_mv) >=1):
396
383
                concat = ''
403
390
                        result[account_line.id] = concat + '...'
404
391
                        break
405
392
                    rup_id+=1
406
 
        print 'result-->',result
407
393
        return result
408
394
 
409
 
    def get_date(self, form):
410
 
        """
411
 
        获取 move.lines 的日期区间
412
 
        """
413
 
        period_from_id = form['period_from']
414
 
        period_to_id = form['period_to']
415
 
        period_obj = self.pool.get('account.period')
416
 
        period_start_obj = period_obj.read(self.cr, self.uid, period_from_id, ['date_start'])
417
 
        period_end_obj = period_obj.read(self.cr, self.uid, period_to_id, ['date_stop'])
418
 
        borne_min = period_start_obj['date_start']
419
 
        borne_max = period_end_obj['date_stop']
420
 
 
421
 
        self.date_borne = {
422
 
            'min_date': borne_min,
423
 
            'max_date': borne_max,
424
 
            }
425
 
        return self.date_borne
426
 
 
427
 
    def get_threecolumns_ledger_type(self, form):
428
 
        if form.get('product',''):
429
 
            self.sql_condition = " AND l.product_id ='"+str(form['product'])+"'"
430
 
        if form.get('partner',''):
431
 
            self.sql_condition = " AND l.partner_id ='"+str(form['partner'])+"'"
 
395
    def get_threecolumns_ledger_type(self, data):
 
396
        if data.get('product', False):
 
397
            self.sql_condition = " AND l.product_id ='"+str(data['product'][0])+"'"
 
398
            self.product = data['product'][0]
 
399
        if data.get('partner', False):
 
400
            self.sql_condition = " AND l.partner_id ='"+str(data['partner'][0])+"'"
 
401
            self.product = data['partner'][0]
432
402
        return self.sql_condition
433
403
 
434
404
 
515
485
        account_obj = self.pool.get('account.account')
516
486
        account_move_line_obj = self.pool.get('account.move.line')
517
487
        account_child_ids = account_obj.search(self.cr, self.uid, [('parent_id', 'child_of', self.ids)])
518
 
        print 'child_ids:',account_child_ids
519
488
        periods = self._get_periods()
520
489
        for period in periods:
521
490
            lines = []
522
491
            period_balance = 0
523
 
            print '%s - %s'%(period.date_start,period.date_stop)
524
492
            account_move_line_ids = account_move_line_obj.search(self.cr, self.uid, [('account_id','in',account_child_ids),('date','<=',period.date_stop),('date','>=',period.date_start),('state','=','valid')],order='date')
 
493
            if self.product:
 
494
                account_move_line_ids = account_move_line_obj.search(self.cr, self.uid, [('id','in',account_move_line_ids),('product_id','=',self.product)])
525
495
            for line in account_move_line_obj.browse(self.cr, self.uid, account_move_line_ids):
526
496
                lines.append(line)
527
497
                period_balance += line.debit - line.credit
532
502
                    'period_balance':period_balance,
533
503
                })
534
504
            
535
 
        print 'result:',result        
536
505
        return result
537
506
 
538
507
    def lines(self, account, form, period, day=False):
565
534
            self.cr.execute(sql, (account.id, period['date_stop'], period['date_start'],))
566
535
            res = self.cr.dictfetchall()
567
536
        sum = 0.0
568
 
        print 'res-->',res
569
537
        account_move_line_obj = self.pool.get('account.move.line')
570
538
        for l in res:
571
539
            line = self.pool.get('account.move.line').browse(self.cr, self.uid, l['id'])
623
591
                    l['rate'] = l['credit']/l['amount_currency']
624
592
            l['sum_balance_amount_currency'] = (self._sum_balance_currency_quantiry(l['date'],l['id']))['sum_balance_amount_currency']
625
593
            l['sum_balance_quantity'] = (self._sum_balance_currency_quantiry(l['date'],l['id']))['sum_balance_quantity']
626
 
        print 'res:',res
627
594
        return ['a','b'] 
628
595
 
629
596
    def _sum_solde_account(self, account, form, period=False):
633
600
        if period==False:
634
601
            self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
635
602
                "FROM account_move_line l "\
636
 
                "WHERE l.account_id = "+str(account.id)+" AND l.date<='"+self.all_dete['period_end_date_stop']+"' AND l.date>='"+self.all_dete['period_start_date_start']+"' AND "+self.query+ " "+self.sql_condition)
 
603
                "WHERE l.account_id = "+str(account.id)+" AND l.date<='"+self.all_date['period_end_date_stop']+"' AND l.date>='"+self.all_date['period_start_date_start']+"' AND "+self.query+ " "+self.sql_condition)
637
604
        else:
638
605
            self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
639
606
                "FROM account_move_line l "\
661
628
                 FROM account_move_line l \
662
629
                 WHERE l.state = 'valid' \
663
630
                 AND l.account_id in ("+','.join(map(str, self.pool.get('account.account').search(self.cr, self.uid,
664
 
            [('parent_id', 'child_of', self.ids)])))+") "+ " AND l.date < '" + self.all_dete['period_start_date_start'] +"'"+self.sql_condition)
 
631
            [('parent_id', 'child_of', self.ids)])))+") "+ " AND l.date < '" + self.all_date['period_start_date_start'] +"'"+self.sql_condition)
665
632
        res = self.cr.dictfetchall()
666
633
        sum_begin_solde = (res[0]['debit'] or 0.0) - (res[0]['credit'] or 0.0)
667
634
        if sum_begin_solde == 0:
671
638
        else:
672
639
            result['direction'] = u'贷'
673
640
        result['sum_begin_solde'] = abs(sum_begin_solde or 0.0)
674
 
        result['begin_date'] = self.all_dete['period_start_date_start']
675
 
        print 'sum---->',result
 
641
        result['begin_date'] = self.all_date['period_start_date_start']
676
642
        return result
677
643
 
678
644
    def _sum_year_amount_solde(self, date):
682
648
        result = {
683
649
            'end_date':'',
684
650
            'direction':'',
685
 
            'debit':'',
686
 
            'credit':'',
 
651
            'quantity':0,
 
652
            'debit':0,
 
653
            'credit':0,
687
654
            'balance':0,
688
655
        }
689
 
        self.cr.execute("SELECT sum(debit) as debit , sum(credit) as credit  "\
 
656
        self.cr.execute("SELECT sum(quantity) as quantity ,sum(debit) as debit , sum(credit) as credit  "\
690
657
                "FROM account_move_line l "\
691
658
                "WHERE l.account_id in ("+','.join(map(str, self.pool.get('account.account').search(self.cr, self.uid,
692
 
            [('parent_id', 'child_of', self.ids)])))+") "+ " AND l.state='valid' AND l.date <= '" + date +"'"+ " AND l.date >= '" + self.all_dete['fiscalyear_obj_date_start']  + "'"+self.sql_condition)
 
659
            [('parent_id', 'child_of', self.ids)])))+") " \
 
660
                + " AND l.state='valid' AND l.date <= '" + date +"'" \
 
661
                + " AND l.date >= '" + self.all_date['fiscalyear_obj_date_start']  + "'"+self.sql_condition)
693
662
        res = self.cr.dictfetchall()
694
663
        sum_year_amount_solde = (res[0]['debit'] or 0.0) - (res[0]['credit'] or 0.0)
695
664
        if sum_year_amount_solde == 0:
699
668
        else:
700
669
            result['direction'] = u'贷'
701
670
        result['balance'] = abs(sum_year_amount_solde or 0.0)
702
 
        result['end_date'] = self.all_dete['fiscalyear_obj_date_start']
703
 
        result['debit'] = res[0]['debit']
704
 
        result['credit'] = res[0]['credit']
 
671
        result['end_date'] = self.all_date['fiscalyear_obj_date_start']
 
672
        result['quantity'] = res[0]['quantity'] or 0
 
673
        result['debit'] = res[0]['debit'] or 0 
 
674
        result['credit'] = res[0]['credit'] or 0
 
675
        print 'sum--->',result
705
676
        return result
706
677
 
707
678
    def _sum_amount_currency_quantiry(self, start_date = False, end_date = False):
708
679
        """
709
680
        获取外币、数量合计值
710
681
        """
 
682
        print '%s++++++%s'%(start_date,end_date)
711
683
        result = {
712
684
            'sum_debit_amount_currency':0.00,
713
685
            'sum_credit_amount_currency':0.00,
803
775
        """
804
776
        外币期初余额
805
777
        """
806
 
        result = self._sum_balance_currency_quantiry(date = self.all_dete['period_start_date_start'])
 
778
        result = self._sum_balance_currency_quantiry(date = self.all_date['period_start_date_start'])
807
779
        return result
808
780
 
809
781
    def _sum_year_balance_amount_currency(self, period):
817
789
        """
818
790
        外币本年借、贷合计
819
791
        """
820
 
        result = self._sum_amount_currency_quantiry(self.all_dete['fiscalyear_obj_date_start'], period['date_stop'])
 
792
        result = self._sum_amount_currency_quantiry(self.all_date['fiscalyear_obj_date_start'], period['date_stop'])
821
793
        return result
822
794
 
823
795
    def _sum_amount_currency(self, period):
824
796
        """
825
797
        外币期间借、贷合计
826
798
        """
827
 
        result = self._sum_amount_currency_quantiry(self.all_dete['period_start_date_start'],self.all_dete['period_end_date_stop'])
 
799
        result = self._sum_amount_currency_quantiry(self.all_date['period_start_date_start'],self.all_date['period_end_date_stop'])
828
800
        return result
829
801
 
830
802
    def _sum_year_quantity(self, period):
831
803
        """
832
804
        数量本年借、贷合计
833
805
        """
834
 
        result = self._sum_amount_currency_quantiry(self.all_dete['fiscalyear_obj_date_start'], period['date_stop'])
 
806
        print '%s=======%s'%(self.all_date['fiscalyear_obj_date_start'], period)
 
807
        result = self._sum_amount_currency_quantiry(self.all_date['fiscalyear_obj_date_start'], period.date_stop)
835
808
        return result
836
809
 
837
810
    def _sum_amount_quantity(self, form, period=False):
838
811
        """
839
812
        数量期间借、贷合计
840
813
        """
841
 
        result = self._sum_amount_currency_quantiry( self.all_dete['period_start_date_start'], self.all_dete['period_end_date_stop'])
 
814
        result = self._sum_amount_currency_quantiry( self.all_date['period_start_date_start'], self.all_date['period_end_date_stop'])
842
815
        return result
843
816
 
844
817
    def _sum_begin_balance_quantity(self):
845
818
        """
846
819
        数量期初余额
847
820
        """
848
 
        result = self._sum_balance_currency_quantiry(date = self.all_dete['period_start_date_start'])
 
821
        result = self._sum_balance_currency_quantiry(date = self.all_date['period_start_date_start'])
849
822
        return result
850
823
 
851
824
    def _sum_year_balance_quantity(self,period):
864
837
        if period==False:
865
838
            self.cr.execute("SELECT sum(debit) "\
866
839
                "FROM account_move_line l "\
867
 
                "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" +self.all_dete['period_end_date_stop'] + "'" +  " AND l.date > '" + self.all_dete['period_start_date_start'] +"'"+self.sql_condition)
 
840
                "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" +self.all_date['period_end_date_stop'] + "'" +  " AND l.date > '" + self.all_date['period_start_date_start'] +"'"+self.sql_condition)
868
841
        else:
869
842
            self.cr.execute("SELECT sum(debit) "\
870
843
                "FROM account_move_line l "\
881
854
        if period==False:
882
855
            self.cr.execute("SELECT sum(credit) "\
883
856
                "FROM account_move_line l "\
884
 
                "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" +self.all_dete['period_end_date_stop'] + "'" +  " AND l.date > '" + self.all_dete['period_start_date_start'] +"'"+self.sql_condition)
 
857
                "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" +self.all_date['period_end_date_stop'] + "'" +  " AND l.date > '" + self.all_date['period_start_date_start'] +"'"+self.sql_condition)
885
858
        else:
886
859
            self.cr.execute("SELECT sum(credit) "\
887
860
                "FROM account_move_line l "\
889
862
        ## Add solde init to the result
890
863
        sum_credit = self.cr.fetchone()[0] or 0.0
891
864
        return sum_credit
892
 
 
 
865
        
893
866
    def _sum_solde(self, form, period=False):
894
867
        """
895
868
        余额期间总计
899
872
        if period==False:
900
873
             self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
901
874
                "FROM account_move_line l "\
902
 
                "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" +self.all_dete['period_end_date_stop'] + "'" +  " AND l.date > '" + self.all_dete['period_start_date_start'] +"'"+self.sql_condition)
 
875
                "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" +self.all_date['period_end_date_stop'] + "'" +  " AND l.date > '" + self.all_date['period_start_date_start'] +"'"+self.sql_condition)
903
876
        else:
904
877
            self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
905
878
                "FROM account_move_line l "\
999
972
report_sxw.report_sxw('report.account.threecolumns_ledger', 'account.account', 'addons/oecn_account_print/report/threecolumns_ledger.rml', parser=detail_ledger_parser, header=False)
1000
973
        
1001
974
#数量金额明细帐
1002
 
report_sxw.report_sxw('report.account.stock_ledger', 'account.account', 'addons/oecn_account_print/report/stock_ledger.odt', parser=detail_ledger_parser, header=False)
 
975
report_sxw.report_sxw('report.account.stock_ledger', 'account.account', 'addons/oecn_account_print/report/stock_ledger.rml', parser=detail_ledger_parser, header=False)
1003
976
 
1004
977
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: