コード例 #1
0
    def post(self, request, **kwargs):
        """
        Post Settings
        """
        schedule_enabled = request.data.get('schedule_enabled')
        assert_valid(schedule_enabled is not None, 'Schedule enabled cannot be null')

        hours = request.data.get('hours')
        assert_valid(hours is not None, 'Hours cannot be left empty')

        email_added = request.data.get('added_email')
        emails_selected = request.data.get('selected_email')

        workspace_schedule_settings = schedule_sync(
            workspace_id=kwargs['workspace_id'],
            schedule_enabled=schedule_enabled,
            hours=hours,
            email_added=email_added,
            emails_selected=emails_selected
        )

        return Response(
            data=WorkspaceScheduleSerializer(workspace_schedule_settings).data,
            status=status.HTTP_200_OK
        )
コード例 #2
0
ファイル: views.py プロジェクト: ashwin1111/fyle-intacct-api
    def get(self, request, *args, **kwargs):
        """
        Get task logs by ids
        """
        task_log_ids = self.request.query_params.getlist('id', [])

        assert_valid(task_log_ids != [], 'task log ids not found')

        task_logs = TaskLog.objects.filter(id__in=task_log_ids).all()

        return Response(
            data=self.serializer_class(task_logs, many=True).data,
            status=status.HTTP_200_OK
        )
コード例 #3
0
    def post(self, request, *args, **kwargs):
        """
        Post workspace general settings
        """
        general_settings_payload = request.data

        assert_valid(general_settings_payload is not None,
                     'Request body is empty')

        workspace_id = kwargs['workspace_id']

        general_settings = create_or_update_general_settings(
            general_settings_payload, workspace_id)
        return Response(data=self.serializer_class(general_settings).data,
                        status=status.HTTP_200_OK)
コード例 #4
0
ファイル: views.py プロジェクト: ashwin1111/fyle-intacct-api
    def post(self, request, *args, **kwargs):
        """
        Create general mappings
        """
        general_mapping_payload = request.data

        assert_valid(general_mapping_payload is not None, 'Request body is empty')

        mapping_utils = MappingUtils(kwargs['workspace_id'])

        general_mapping = mapping_utils.create_or_update_general_mapping(general_mapping_payload)

        return Response(
            data=self.serializer_class(general_mapping).data,
            status=status.HTTP_200_OK
        )
コード例 #5
0
ファイル: views.py プロジェクト: ashwin1111/fyle-intacct-api
    def post(self, request, *args, **kwargs):
        """
        Create bill from expense group
        """
        expense_group_id = request.data.get('expense_group_id')
        task_log_id = request.data.get('task_log_id')

        assert_valid(expense_group_id is not None,
                     'expense group id not found')
        assert_valid(task_log_id is not None, 'Task Log id not found')

        expense_group = ExpenseGroup.objects.get(pk=expense_group_id)
        task_log = TaskLog.objects.get(pk=task_log_id)

        create_bill(expense_group, task_log)

        return Response(data={}, status=status.HTTP_200_OK)
コード例 #6
0
    def post(self, request, **kwargs):
        """
        Post of Fyle Credentials
        """
        try:
            authorization_code = request.data.get('code')

            workspace = Workspace.objects.get(id=kwargs['workspace_id'])

            refresh_token = auth_utils.generate_fyle_refresh_token(
                authorization_code)['refresh_token']
            fyle_user = auth_utils.get_fyle_user(refresh_token)
            org_id = fyle_user['org_id']
            org_name = fyle_user['org_name']

            assert_valid(
                workspace.fyle_org_id and workspace.fyle_org_id == org_id,
                'Please select the correct Fyle account - {0}'.format(
                    workspace.name))

            workspace.name = org_name
            workspace.fyle_org_id = org_id
            workspace.save(update_fields=['name', 'fyle_org_id'])

            fyle_credentials, _ = FyleCredential.objects.update_or_create(
                workspace_id=kwargs['workspace_id'],
                defaults={
                    'refresh_token': refresh_token,
                })

            return Response(
                data=FyleCredentialSerializer(fyle_credentials).data,
                status=status.HTTP_200_OK)
        except fyle_exc.UnauthorizedClientError:
            return Response({'message': 'Invalid Authorization Code'},
                            status=status.HTTP_403_FORBIDDEN)
        except fyle_exc.NotFoundClientError:
            return Response({'message': 'Fyle Application not found'},
                            status=status.HTTP_404_NOT_FOUND)
        except fyle_exc.WrongParamsError:
            return Response({'message': 'Some of the parameters are wrong'},
                            status=status.HTTP_400_BAD_REQUEST)
        except fyle_exc.InternalServerError:
            return Response({'message': 'Wrong/Expired Authorization code'},
                            status=status.HTTP_401_UNAUTHORIZED)
コード例 #7
0
    def create_or_update_general_mapping(self, general_mapping: Dict):
        """
        Create or update general mapping
        :param general_mapping: general mapping payload
        :return:
        """
        configuration = Configuration.objects.get(
            workspace_id=self.__workspace_id)

        project_setting: MappingSetting = MappingSetting.objects.filter(
            workspace_id=self.__workspace_id,
            destination_field='PROJECT').first()

        if configuration.corporate_credit_card_expenses_object == 'CHARGE_CARD_TRANSACTION':
            assert_valid(
                'default_charge_card_name' in general_mapping
                and general_mapping['default_charge_card_name'],
                'default charge card name field is blank')
            assert_valid(
                'default_charge_card_id' in general_mapping
                and general_mapping['default_charge_card_id'],
                'default charge card id field is blank')

        elif configuration.corporate_credit_card_expenses_object == 'BILL':
            assert_valid(
                'default_ccc_vendor_name' in general_mapping
                and general_mapping['default_ccc_vendor_name'],
                'default ccc vendor name field is blank')
            assert_valid(
                'default_ccc_vendor_id' in general_mapping
                and general_mapping['default_ccc_vendor_id'],
                'default ccc vendor id field is blank')

        elif configuration.corporate_credit_card_expenses_object == 'EXPENSE_REPORT':
            assert_valid(
                'default_ccc_expense_payment_type_name' in general_mapping
                and general_mapping['default_ccc_expense_payment_type_name'],
                'default ccc expense payment type name is blank')
            assert_valid(
                'default_ccc_expense_payment_type_id' in general_mapping
                and general_mapping['default_ccc_expense_payment_type_id'],
                'default ccc expense payment type id is blank')

        if project_setting:
            assert_valid(
                'default_item_name' in general_mapping
                and general_mapping['default_item_name'],
                'default item name field is blank')
            assert_valid(
                'default_item_id' in general_mapping
                and general_mapping['default_item_id'],
                'default item id field is blank')

        if configuration.sync_fyle_to_sage_intacct_payments:
            assert_valid(
                'payment_account_name' in general_mapping
                and general_mapping['payment_account_name'],
                'payment account name field is blank')
            assert_valid(
                'payment_account_id' in general_mapping
                and general_mapping['payment_account_id'],
                'payment account id field is blank')

        if configuration.import_tax_codes:
            assert_valid(
                'default_tax_code_id' in general_mapping
                and general_mapping['default_tax_code_id'],
                'default tax code id is blank')
            assert_valid(
                'default_tax_code_name' in general_mapping
                and general_mapping['default_tax_code_name'],
                'default tax code name is blank')

        general_mapping_object, _ = GeneralMapping.objects.update_or_create(
            workspace_id=self.__workspace_id,
            defaults={
                'location_entity_name': general_mapping['location_entity_name'],
                'location_entity_id': general_mapping['location_entity_id'],
                'default_location_name': general_mapping['default_location_name'],
                'default_location_id': general_mapping['default_location_id'],
                'payment_account_name': general_mapping['payment_account_name'],
                'payment_account_id': general_mapping['payment_account_id'],
                'default_department_name': general_mapping['default_department_name'],
                'default_department_id': general_mapping['default_department_id'],
                'default_class_name': general_mapping['default_class_name'],
                'default_class_id': general_mapping['default_class_id'],
                'default_project_name': general_mapping['default_project_name'],
                'default_project_id': general_mapping['default_project_id'],
                'default_charge_card_name': general_mapping['default_charge_card_name'],
                'default_charge_card_id': general_mapping['default_charge_card_id'],
                'default_ccc_vendor_name': general_mapping['default_ccc_vendor_name'],
                'default_ccc_vendor_id': general_mapping['default_ccc_vendor_id'],
                'default_item_name': general_mapping['default_item_name'],
                'default_item_id': general_mapping['default_item_id'],
                'default_tax_code_id': general_mapping['default_tax_code_id'],
                'default_tax_code_name': general_mapping['default_tax_code_name'],
                'default_reimbursable_expense_payment_type_name': \
                    general_mapping['default_reimbursable_expense_payment_type_name'],
                'default_reimbursable_expense_payment_type_id': \
                    general_mapping['default_reimbursable_expense_payment_type_id'],
                'default_ccc_expense_payment_type_name': general_mapping['default_ccc_expense_payment_type_name'],
                'default_ccc_expense_payment_type_id': general_mapping['default_ccc_expense_payment_type_id'],
                'use_intacct_employee_departments': general_mapping['use_intacct_employee_departments'],
                'use_intacct_employee_locations': general_mapping['use_intacct_employee_locations']
            }
        )

        if configuration.reimbursable_expenses_object == 'BILL':
            schedule_ap_payment_creation(
                sync_fyle_to_sage_intacct_payments=configuration.
                sync_fyle_to_sage_intacct_payments,
                workspace_id=self.__workspace_id)

        if configuration.reimbursable_expenses_object == 'EXPENSE_REPORT':
            schedule_sage_intacct_reimbursement_creation(
                sync_fyle_to_sage_intacct_payments=configuration.
                sync_fyle_to_sage_intacct_payments,
                workspace_id=self.__workspace_id)

        if general_mapping_object.default_charge_card_name:
            schedule_auto_map_charge_card_employees(self.__workspace_id)

        return general_mapping_object