~openbig/bigconsulting/changes_in_discount_field

« back to all changes in this revision

Viewing changes to account_invoice_cash_discount/account_invoice_cash_discount.py

  • Committer: husen
  • Date: 2010-08-05 10:29:25 UTC
  • mfrom: (61.1.3 bigconsulting)
  • Revision ID: husen@husen-laptop-20100805102925-261ll8vlea57f1uj
committed tax changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
class account_payment_term_line(osv.osv):
53
53
    _inherit = "account.payment.term.line"
54
54
    _columns = {
55
 
        'day_tolerance': fields.integer('Days Tolerance', digits=(16,6),required=True),
 
55
        'day_tolerance': fields.integer('Days Tolerance', digits=(16,6)),
56
56
        'payment_id': fields.many2one('account.payment.term', 'Payment Term', required=False, select=True),
57
57
        'compl_cash_discount':fields.boolean('Use Complete Cash Discount'),
58
58
    }
 
59
    _defaults = {
 
60
        'day_tolerance':lambda *a :0,
 
61
        }
59
62
account_payment_term_line()
60
63
 
61
64
class account_invoice(osv.osv):
526
529
 
527
530
    def button_confirm(self, cr, uid, ids, context={}):
528
531
        done = []
 
532
        tax_obj = self.pool.get('account.tax')
529
533
        res_currency_obj = self.pool.get('res.currency')
530
534
        res_users_obj = self.pool.get('res.users')
531
535
        account_move_obj = self.pool.get('account.move')
576
580
                amount = res_currency_obj.compute(cr, uid, st.currency.id,
577
581
                        company_currency_id, move.amount, context=context,
578
582
                        account=acc_cur)
579
 
#                if move.reconcile_id and move.reconcile_id.line_new_ids:
580
 
#                    for newline in move.reconcile_id.line_new_ids:
581
 
#                        amount += newline.amount
582
583
 
 
584
                st_tax_amount = 0.00
 
585
                st_base_code_id = False
 
586
                
 
587
                if move.tax_id:
 
588
                    tax = tax_obj.compute(cr, uid, [move.tax_id], move.amount, 1.00)[0]
 
589
                    st_tax_amount = tax['amount']
 
590
                    st_base_code_id = tax['base_code_id']
 
591
                        
583
592
                val = {
584
593
                    'name': move.name,
585
594
                    'date': move.date,
593
602
                    'journal_id': st.journal_id.id,
594
603
                    'period_id': st.period_id.id,
595
604
                    'currency_id': st.currency.id,
 
605
                    'tax_code_id':st_base_code_id,
 
606
                    'account_tax_id':move.tax_id.id,
 
607
                    'tax_amount':move.amount,
596
608
                }
597
 
 
598
609
                amount = res_currency_obj.compute(cr, uid, st.currency.id,
599
610
                        company_currency_id, move.amount, context=context,
600
611
                        account=acc_cur)
614
625
                                account=acc_cur)
615
626
                    val['amount_currency'] = amount_cur
616
627
 
617
 
                torec.append(account_move_line_obj.create(cr, uid, val , context=context))
 
628
                torec.append(account_move_line_obj.create(cr, uid, val, context=context))
 
629
                
618
630
                newline_sum = 0.0
619
631
                if move.reconcile_id and move.reconcile_id.line_new_ids:
620
632
                    for newline in move.reconcile_id.line_new_ids:
720
732
                            'amount_currency': amount_currency,
721
733
                            'currency_id': currency_id,
722
734
                            }, context=context)
723
 
 
 
735
                        
724
736
                account_move_line_obj.create(cr, uid, {
725
737
                    'name': move.name,
726
738
                    'date': move.date,
728
740
                    'move_id': move_id,
729
741
                    'partner_id': ((move.partner_id) and move.partner_id.id) or False,
730
742
                    'account_id': account_id,
731
 
                    'credit': (((amount-newline_sum) < 0) and -(amount-newline_sum)) or 0.0,
732
 
                    'debit': (((amount-newline_sum) > 0) and (amount-newline_sum)) or 0.0,
 
743
                    'credit': (((amount+st_tax_amount-newline_sum) < 0) and -(amount+st_tax_amount-newline_sum)) or 0.0,
 
744
                    'debit': (((amount+st_tax_amount-newline_sum) > 0) and (amount+st_tax_amount-newline_sum)) or 0.0,
733
745
                    'statement_id': st.id,
734
746
                    'journal_id': st.journal_id.id,
735
747
                    'period_id': st.period_id.id,
737
749
                    'currency_id': currency_id,
738
750
                    }, context=context)
739
751
 
 
752
                account_move_line_obj.write(cr, uid, [x.id for x in
 
753
                        account_move_obj.browse(cr, uid, move_id,
 
754
                            context=context).line_id], {'statement_id': st.id,})
 
755
                
740
756
                for line in account_move_line_obj.browse(cr, uid, [x.id for x in
741
757
                        account_move_obj.browse(cr, uid, move_id,
742
758
                            context=context).line_id],
743
759
                        context=context):
 
760
                    
744
761
                    if line.state <> 'valid':
745
762
                        raise osv.except_osv(_('Error !'),
746
763
                                _('Account move line "%s" is not valid') % line.name)
749
766
                    torec += map(lambda x: x.id, move.reconcile_id.line_ids)
750
767
                    #try:
751
768
                    if abs(move.reconcile_amount-move.amount)<0.0001:
752
 
 
753
769
                        writeoff_acc_id = False
754
770
                        #There should only be one write-off account!
755
771
                        for entry in move.reconcile_id.line_new_ids:
756
772
                            writeoff_acc_id = entry.account_id.id
757
773
                            break
758
 
 
759
774
                        account_move_line_obj.reconcile(cr, uid, torec, 'statement', writeoff_acc_id=writeoff_acc_id, writeoff_period_id=st.period_id.id, writeoff_journal_id=st.journal_id.id, context=context)
760
775
                    else:
761
776
                        account_move_line_obj.reconcile_partial(cr, uid, torec, 'statement', context)
771
786
 
772
787
account_bank_statement()
773
788
 
 
789
class account_bank_statement_line(osv.osv):
 
790
    _inherit="account.bank.statement.line"
 
791
    
 
792
    def _get_account(self, cr, uid, context={}):
 
793
        account_id = self.pool.get('account.account').search(cr, uid, [('type','!=','view')])[0]
 
794
        if account_id:
 
795
            return account_id
 
796
        else:
 
797
            return False
 
798
        
 
799
    def _get_tax(self, cr, uid, context={}):
 
800
        tax_id = self.pool.get('account.tax').search(cr, uid, [])
 
801
        if tax_id:
 
802
            return tax_id[0]
 
803
        else:
 
804
            return False    
 
805
    _columns = {
 
806
        'tax_id': fields.many2one('account.tax', 'Tax'),
 
807
    }
 
808
    _defaults = {
 
809
        'account_id': _get_account,
 
810
        'tax_id': _get_tax,
 
811
    }
 
812
account_bank_statement_line()
774
813
 
775
814
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
776
815