<commit_before>#!/usr/bin/python
# -*- encoding: utf-8 -*-
###############################################################################
#    Module Writen to OpenERP, Open Source Management Solution
#    Copyright (C) OpenERP Venezuela (<http://www.vauxoo.com>).
#    All Rights Reserved
############# Credits #########################################################
#    Coded by: <NAME> <<EMAIL>>
#    Planified by: <NAME> <<EMAIL>>
#    Audited by: <NAME> <<EMAIL>>
###############################################################################
#    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 datetime import datetime
from dateutil.relativedelta import relativedelta
from openerp.tests.common import TransactionCase
import csv
import os

class TestLoanCompute(TransactionCase):

    def setUp(self):
        super(TestLoanCompute, self).setUp()
        self.imd_obj = self.registry('ir.model.data')
        self.hr_loan_obj = self.registry('hr.loan')
        self.hr_contract_obj = self.registry('hr.contract')
        self.loan_list_brw = list()

    def dataloan(self):
        cr, uid = self.cr, self.uid

        contract_id = self.hr_contract_obj.create(cr, uid, {
                'name' : 'Ashley Presley Contract',
                'employee_id' : 13, #Ashley Presley
                'type_id' : 1, #Employee
                'wage' : 10000,
                'struct_id' : 4, #Salary with loan
            })

        data_loan = [
                {
                'name' : '<NAME>',
                'amount_approved' : 6000,
                'share_quantity' : 8,
                'payment_type' : 'monthly',
                'date_start' : '2014-10-29',
                'employee_id' : contract_id,
                'partner_id' : 13,
                },
                 {
                'name' : '<NAME>',
                'amount_approved' : 3000,
                'share_quantity' : 4,
                'payment_type' : 'fortnightly',
                'date_start' : '2014-10-24',
                'employee_id' : contract_id,
                'partner_id' : 13,
                }
            ]

        self.loan_list = list()

        for loan_data in data_loan:
            loan_id = self.hr_loan_obj.create(cr, uid, loan_data)
            self.loan_list.append(loan_id)

        return True

    def test1(self):
        cr, uid = self.cr, self.uid
        #loan_brw = self.loan_list_brw[0]

        #share_1 = loan_brw.share_ids[0]

        #if share_1.payment_date != '2014-10-31':
        #    self.assertEquals('Error! in shares payment_date')
        return True

    def test_compute_shares(self):
        cr, uid = self.cr, self.uid

        data_ok = self.dataloan()

        for loan_id in self.loan_list:

            self.hr_loan_obj.compute_shares(cr, uid, loan_id)
            loan_brw = self.hr_loan_obj.browse(cr, uid, loan_id)

            self.loan_list_brw.append(loan_brw)

            current_date = datetime.strptime(loan_brw.date_start, '%Y-%m-%d')

            if loan_brw.share_quantity != len(loan_brw.share_ids):
                self.assertEquals('Error! in shares quantity')

        test1_ok = self.test1()

<commit_msg>[IMP] ready test just for Loan: date_end, share amount each share, payment date each share and state each share<commit_after>#!/usr/bin/python
# -*- encoding: utf-8 -*-
###############################################################################
#    Module Writen to OpenERP, Open Source Management Solution
#    Copyright (C) OpenERP Venezuela (<http://www.vauxoo.com>).
#    All Rights Reserved
############# Credits #########################################################
#    Coded by: <NAME> <<EMAIL>>
#    Planified by: <NAME> <<EMAIL>>
#    Audited by: <NAME> <<EMAIL>>
###############################################################################
#    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 datetime import datetime
from dateutil.relativedelta import relativedelta
from openerp.tests.common import TransactionCase
import csv
import os

class TestLoanCompute(TransactionCase):

    def setUp(self):
        super(TestLoanCompute, self).setUp()
        self.imd_obj = self.registry('ir.model.data')
        self.hr_loan_obj = self.registry('hr.loan')
        self.hr_contract_obj = self.registry('hr.contract')
        self.loan_list_brw = list()

    def dataloan(self):
        cr, uid = self.cr, self.uid

        contract_id = self.hr_contract_obj.create(cr, uid, {
                'name' : '<NAME>',
                'employee_id' : 13, #<NAME>
                'type_id' : 1, #Employee
                'wage' : 10000,
                'struct_id' : 4, #Salary with loan
            })

        data_loan = [
                {
                'name' : '<NAME>',
                'amount_approved' : 6000,
                'share_quantity' : 8,
                'payment_type' : 'monthly',
                'date_start' : '2014-10-29',
                'employee_id' : contract_id,
                'partner_id' : 13,
                },
                 {
                'name' : '<NAME>',
                'amount_approved' : 3000,
                'share_quantity' : 5,
                'payment_type' : 'fortnightly',
                'date_start' : '2015-01-15',
                'employee_id' : contract_id,
                'partner_id' : 13,
                }
            ]

        self.loan_list = list()

        for loan_data in data_loan:
            loan_id = self.hr_loan_obj.create(cr, uid, loan_data)
            self.loan_list.append(loan_id)

        return True

    def share_test(self, loan_brw, amount):
        error_msg_share_test = 'Error! in share amount'
        for share in loan_brw.share_ids:
            if share.share != amount or share.state != 'unpaid':
                self.assertEquals(error_msg_share_test)

    def date_test(self, loan_brw, ind, date):
        error_msg_date_test = 'Error! in shares payment_date'
        share = loan_brw.share_ids[ind]
        if share.payment_date != date:
            self.assertEquals(error_msg_date_test)

    def date_test_end(self, loan_brw, date):
        error_msg_date_end = 'Error! in loan end date'
        if loan_brw.date_stop != date:
            self.assertEquals(error_msg_date_end)

    def loan_test_1(self):
        if self.loan_list_brw:
            loan_brw = self.loan_list_brw[0]

            self.share_test(loan_brw, 750)
            self.date_test_end(loan_brw, '2015-06-01')
            self.date_test(loan_brw, 0, '2014-10-31')
            self.date_test(loan_brw, 1, '2014-11-30')
            self.date_test(loan_brw, 2, '2014-12-31')
            self.date_test(loan_brw, 3, '2015-01-31')
            self.date_test(loan_brw, 4, '2015-02-28')
            self.date_test(loan_brw, 5, '2015-03-31')
            self.date_test(loan_brw, 6, '2015-04-30')
            self.date_test(loan_brw, 7, '2015-05-31')

        return True

    def loan_test_2(self):
        if self.loan_list_brw:
            loan_brw = self.loan_list_brw[1]

            self.share_test(loan_brw, 600)
            self.date_test_end(loan_brw, '2015-04-01')
            self.date_test(loan_brw, 0, '2015-01-31')
            self.date_test(loan_brw, 1, '2015-02-15')
            self.date_test(loan_brw, 2, '2015-02-28')
            self.date_test(loan_brw, 3, '2015-03-15')
            self.date_test(loan_brw, 4, '2015-03-31')

        return True

    def test_compute_shares(self):
        cr, uid = self.cr, self.uid

        data_ok = self.dataloan()

        for loan_id in self.loan_list:

            self.hr_loan_obj.compute_shares(cr, uid, loan_id)
            loan_brw = self.hr_loan_obj.browse(cr, uid, loan_id)

            self.loan_list_brw.append(loan_brw)

            current_date = datetime.strptime(loan_brw.date_start, '%Y-%m-%d')

            if loan_brw.share_quantity != len(loan_brw.share_ids):
                self.assertEquals('Error! in shares quantity')

        test1_ok = self.loan_test_1()
        test1_ok = self.loan_test_2()


{'fraction_non_alphanumeric': 0.16486772486772486, 'fraction_numerical': 0.02582010582010582, 'mean_word_length': 2.2679806362378976, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1350751', 'n_tokens_mistral': 3149, 'n_tokens_neox': 2799, 'n_words': 679}