def test_calculate_profit_of_proforma_spec(self): date = '20201014' modified_df, cost_file_name = helpers.prepare_data_frame_based_on_proforma_date( date) cost = helpers.calculate_cost_of_spec(modified_df, **self.spec) profit = self.spec['price'] - cost self.assertEqual(round(profit, 2), 120533012)
def test_calculate_cost_of_proforma_spec_400v(self): date = '20201014' self.spec['voltage'] = 400 modified_df, cost_file_name = helpers.prepare_data_frame_based_on_proforma_date( date) cost = helpers.calculate_cost_of_spec(modified_df, **self.spec) self.assertEqual(round(cost, 2), 879466988)
def test_handle_spec_not_in_routine_costs(self): date = '20201014' self.spec['power'] = 2000 modified_df, cost_file_name = helpers.prepare_data_frame_based_on_proforma_date( date) cost = helpers.calculate_cost_of_spec(modified_df, **self.spec) self.assertEqual(cost, None)
def test_get_adjusted_routine_cost(self): material_payload = { 'silicon': 250000, 'cu': 2100000, 'alu': 500000, 'steel': 150000, 'dicast': 220000, } adjusted_df = helpers.get_adjusted_cost(self.spec.get('date'), material_payload) cost = calculate_cost_of_spec(adjusted_df, **self.spec) self.assertEqual(cost, 811370988)
def test_perform_discount(self): discount = { 'lte__90': 10, 'gt__90': 10, } date = '20201014' self.spec['price'] = 1000000000 modified_df, cost_file_name = helpers.prepare_data_frame_based_on_proforma_date( date) cost = helpers.calculate_cost_of_spec(modified_df, **self.spec) profit = helpers.calculate_spec_profit_with_discount( cost, self.spec, discount_dict=discount) self.assertEqual(profit['profit'], 20533012)
def test_adjust_materials(self): material_payload = { 'silicon': 250000, 'cu': 2100000, 'alu': 500000, 'steel': 150000, 'dicast': 220000, } date = '20201014' modified_df, cost_file_name = helpers.prepare_data_frame_based_on_proforma_date( date) response = helpers.adjust_df_materials(modified_df, material_payload) adjusted_df = response['adjusted_df'] adjusted_material_payload = response['adjusted_materials'] spec_cost = helpers.calculate_cost_of_spec(adjusted_df, **self.spec) self.assertEqual(adjusted_material_payload['silicon'], material_payload['silicon']) self.assertEqual(spec_cost, 811370988)
def cost_routine(self): from request.helpers import helpers prof_date = self.xpref_id.date_fa date_greg = prof_date.togregorian() date = helpers.get_date_str(date_greg) modified_df, cost_file_name = helpers.prepare_data_frame_based_on_proforma_date( date) cost = helpers.calculate_cost_of_spec( modified_df, **{ 'code': self.code, 'qty': self.qty, 'power': self.kw, 'price': self.price, 'kw': self.kw, 'rpm': self.rpm, 'voltage': self.voltage, 'im': self.im, 'ip': self.ip, 'ic': self.ic, 'type': self.type, }) return cost
def test_calculate_cost_of_proforma_spec(self): date = '20201014' modified_df, cost_file_name = helpers.prepare_data_frame_based_on_proforma_date( date) cost = helpers.calculate_cost_of_spec(modified_df, **self.spec) self.assertEqual(cost, 879466988)